Creating layout/new layout

edited November 2014 in News & Announcements
hi admin i am stuck in this topic ....
i have a view file in my views with the name home.php which is the home page of my site i have created a variable file in _vairables that is named as home.php and it have following code

<?php

// declared here so we don't have to in each controller's variable file
$CI =& get_instance();

// in your _variables/home.php
$vars['layout'] = 'home';

// or as a page variable in the same file
$pages['home'] = array('layout' => 'home');


// using the fuel_set_var in your view file
fuel_set_var('layout', 'home');


and i have one layout for it in _layouts that is as well named as home.php with the following
<?php $this->load->view('_blocks/header')?>

<?php echo fuel_var('heading');?>

<?php echo fuel_var('body'); ?>




<?php $this->load->view('_blocks/footer')?>

now i am facing two major issues as following
1-in view file home.php the area where i want to show content from admin home page i have to write this code for it to echo it <?php echo fuel_var('body');> otherwise it is not appearing in that place and if i comment that line for body from layout page it also disappears i mean content disappears...what is wrong here

2-second if i add image from admin in body of home page it also not appearing on front side home page while the other pages in admin has different layout i have selected that is main and images are appearing on that pages ..why image is not showing on home page having layout home....please help me i have explained the probem very deeply
advance thanks for every body input

Comments

  • edited November 2014
    1. For the variables file you created, you only need to have the first option:$vars['layout'] = 'home'; The $pages['home'] option is if you are in a variables file other then the home one (which you aren't in this case), and the fuel_set_var option is for if you are in a view file and want to set the variable from that perspective.

    The $body variable is necessary if you are using static view files to create a page. This variable holds the contents of your "views/home.php" view file (not to be confused with the "views/_layouts/home.php" layout file which is the layout).

    2. Regarding your image problem, I would need to know more about how you are entering in your image information in the CMS. If it is simply an "asset" field type, then that will provide a variable you can use in your layout with the same name as the field. So if in your layout, you've defined a field of "feature_image" which has a field type of asset, then in your layout you can use one of the following:
    <?=fuel_var('feature_image')?> // will output variable along with inline editing code <?=$feature_image?> // will only output the variable
    For more on layouts and fields (in particular the asset field type), see the links below:
    http://docs.getfuelcms.com/general/layouts
    http://docs.getfuelcms.com/general/forms#asset
  • edited 4:15PM
    no i am uploading the image in content area i mean in the body section of a home page having layout "home" and i have done the changes for layout of home but still same problem but images are appearing on other pages correctly.
    On home page having home layout when i inspect it ,it says cant load the given url..{img_path('sme1.png')}

    please help me in this....
  • edited 4:15PM
    A few more questions:
    1. Are you using the normal markItUp! editor for editing the body copy of your home page?
    2. Do you see {img_path('sme1.png')} in the "body" field of your home page in the CMS?
    3. In your fuel/application/views/_layouts/home.php file, you have <?=fuel_var('body')?> or simply just <?=$body?>
    4. When you browse to "home" you are getting the error when you inspect that the {img_path('sme1.png')} isn't getting parsed correctly correct?
    5. What version of FUEL are you running?
  • edited 4:15PM
    1-yes i am using the defaulted editor when i installed the fuel
    2-this is the image path in body..test when i preview it,,,,it shows the image in the preview window
    3-let me tell you some thing here that in my view file for home which is in views/home.php the div where i want to show content from cms admin home page i am using this line of code
    <?php echo fuel_var('body'); ?>
    but if i remove this line from here it does not show content from admin page and one thing more i have this same line code in _layouts/home.php if i remove this line from layout of home page the whole home page area is empty means it does not show any thing ..
    in short i have been using this line in my view and layout as well in both places ,removing form either page stops the page from working or showing data
    4-when i browse to home page it showing the alt text of the image but when i inspect it ,it says cant load the given URL.
    5- i am using 1.2 version....



    apart from this i want gallary in fuel how can i do this having ful gallery feature like uploading editing deleting and on front end click able images which show in pop up etc please guide me in this as well

    bundle bundle of thanks you are great man
  • edited 4:15PM
    i have read this and the links all mentioned in the box but i am not very good in coding in fuel code ignitor....
    http://forum.getfuelcms.com/discussion/comment/6381#Comment_6381
  • edited November 2014
    It looks to me like the $body variable isn't running the template parsing. I'm not sure what may be causing that to not happen. If you view source, do you see any other PHP errors in the code?

    For creating a photo gallery, you can create a simple module:
    http://docs.getfuelcms.com/modules/simple

    I would start by creating a table like so:
    CREATE TABLE `photo_gallery` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `image` varchar(255) NOT NULL DEFAULT '', `thumbnail_image` varchar(255) NOT NULL DEFAULT '', `caption` text NOT NULL, `precedence` int(11) NOT NULL, `published` enum('yes','no') NOT NULL DEFAULT 'yes', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    Then you can alter the model to something like the following (this is one we've used in the past):
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Photo_gallery_model extends Base_module_model { public $required = array('image'); public $record_class = 'Photo_gallery_item'; public $has_many = array('tags' => array(FUEL_FOLDER => 'fuel_tags_model')); const GALLERY_DIR = 'gallery'; function __construct() { parent::__construct('photo_gallery'); // table name } function form_fields($values = array(), $related = array()) { $fields = parent::form_fields($values, $related); $fields['image']['folder'] = 'images/gallery'; $fields['image']['hide_options'] = FALSE; $fields['image']['create_thumb'] = TRUE; $fields['image']['width'] = 211; $fields['image']['height'] = 108; $fields['image']['master_dimension'] = 'width'; $fields['image']['comment'] = 'A thumbnail will be automatically created for you if one is not specified in the field below. Dimensions are 800w x 276h.'; $fields['thumbnail_image']['folder'] = 'images/gallery'; $fields['thumbnail_image']['hide_options'] = TRUE; $fields['thumbnail_image']['comment'] = 'If left blank, one will be created for you based on the image specified above. Dimensions are 210w x 108h.'; $fields['precedence']['comment'] = 'Determines order'; return $fields; } function on_after_save($values) { $values = parent::on_after_save($values); if (!empty($values['id'])) { $photo = $this->find_by_key($values['id']); if (!$photo->has_thumbnail_image()) { $photo->create_thumbnail(); } } return $values; } } class Photo_gallery_item_model extends Base_module_record { public $thumb_width = 210; public $thumb_height = 108; function get_image_path($ext = TRUE) { $img = $this->get_image_name('image', $ext); return img_path(Photo_gallery_model::GALLERY_DIR.'/'.$img); } function get_thumbnail_path($ext = TRUE) { $img = $this->get_image_name('thumbnail', $ext); return img_path(Photo_gallery_model::GALLERY_DIR.'/'.$img); } function get_image_name($type = 'image', $ext = TRUE) { if ($type == 'thumb' OR $type == 'thumbnail') { $type = 'thumbnail_image'; } if (!$ext) { $img_arr = explode('.', $this->$type); array_pop($img_arr); $img = implode('.', $img_arr); } else { $img = $this->$type; } return $img; } function get_image_server_path($ext = TRUE) { $img = $this->get_image_name('image', $ext); return assets_server_path(Photo_gallery_model::GALLERY_DIR.'/'.$img, 'images'); } function get_thumbnail_server_path($ext = TRUE) { $img = $this->get_image_name('thumbnail', $ext); return assets_server_path(Photo_gallery_model::GALLERY_DIR.'/'.$img, 'images'); } function get_image_ext() { return end(explode('.', $this->image)); } function create_thumbnail($check_if_exists = TRUE) { $this->_CI->load->library('image_lib'); if ($check_if_exists AND empty($this->thumbnail_image) OR !$check_if_exists) { $gallery_folder = assets_server_path(Photo_gallery_model::GALLERY_DIR, 'images'); $thumb_image = $this->get_image_name('image', FALSE).'_thumb.'.$this->image_ext; // create thumb $config = array(); $config['source_image'] = $this->image_server_path; $config['create_thumb'] = FALSE; $config['new_image'] = assets_server_path(Photo_gallery_model::GALLERY_DIR.'/'.$thumb_image,'images'); $config['width'] = $this->thumb_width; $config['height'] = $this->thumb_height; $config['master_dim'] = 'width'; $config['maintain_ratio'] = TRUE; $this->_CI->image_lib->clear(); $this->_CI->image_lib->initialize($config); if (!$this->_CI->image_lib->resize_and_crop()) { $this->_parent_model->add_error($this->_CI->image_lib->display_errors()); } $this->thumbnail_image = $thumb_image; $this->save(); } return FALSE; } }
    Then in your fuel/application/config/MY_fuel_modules.php, add something like the following if it isn't already there:
    $config['modules']['photo_gallery'] = array( 'preview_path' => 'gallery', );

    Then in your fuel/application/views/_blocks/ folder you can create a block like (.e.g my_gallery.php) the following:
    $gallery = fuel_model('photo_gallery'); foreach($gallery as $image): echo <img src="<?=$image->image_path?>" alt="" /> endforeach;
    Then you can call that block on any page:
    <?=fuel_block('my_block')?>
  • edited 4:15PM
    ohhh great i m going to implement this now but one thing let me ask the gallery page where images will be shown will they be click able to open in lightbox having next previous links.....etc
  • edited 4:15PM
    i have done all this but on gallery page its now showing image or any thing

    echo 'imageimage_path?>" alt="" />';

    when i inspect it ,it says Failed to load the given URL...
  • edited 4:15PM
    What is the URL it is trying to load and does that file exist?
  • edited 4:15PM
    yes the file exists in the images/gallery folder but not showing
  • edited 4:15PM
    on inspection it shows......="<?php echo $image->image_path; ?>"> Failed to load the given URL
  • edited 4:15PM
    if print_r any return vairable in model its also not working
  • edited November 2014
    when i do this it give blank page which mean nothing is coming from model
    $gallery = fuel_model('photo_gallery_model');

    print_r($gallery);
  • edited 4:15PM
    and and please let me know about lightbox for the images
  • edited 4:15PM
    i have tried the code in block/footer.php and in views/gallery.php but same issue as i mentioned above ....
    1-you have not used controller may be that can be issue
    2-i have tried a controller and tried to get the methods of model but no success.

    so after all tries now i am waiting for your kind reply
  • edited 4:15PM
    Doing a print_r on a model variable will most likely make your browser spin because of the recursion of CI objects. So if it is spinning, that's actually a good thing and means that the object exists. A better way to use print_r on those objects is to do:
    print_r($record->values());
    This should be used on a single record object (not an array of record objects which the code above will return.
    $gallery = fuel_model('photo_gallery'); foreach($gallery as $image): print_r($image->values()); endforeach;
    You noted above that when you view source it is showing PHP code not being rendered:
    <?php echo $image->image_path; ?>. Is that correct?
  • edited 4:15PM
    Also, this was just release in the forum which may help with your photo gallery:
    http://forum.getfuelcms.com/discussion/1948/free-source-code-for-my-photo-gallery-module
  • edited November 2014
    i am going to this module but according to its writer may be some bugs are there as code is not properly managed ...
    for the above issue i have tried every thing as suggest but not showing the image
    either i should use the gallerymanager module or either i should use the above code which we are trying to use ...
    but the module is not properly arrange if you could look into it and arrange it like other brilliant modules of the fuel it will be great for me and all other who want to implement gallery in the fuel cms module
    so it will be very great if you could do that i have tried to use the module but useless nothing is working in it.....i am waiting for your input for the module to make it working
  • edited November 2014
    i have tried to get deep in gallerymanager module but un successful please help in this in making it to work
  • edited 4:15PM
    Was anything being displayed when you did the following:
    $gallery = fuel_model('photo_gallery'); foreach($gallery as $image): print_r($image->values()); endforeach;
  • edited 4:15PM
    yes i tried this code right now its giving the output like this
    Array ( [id] => 1 [image] => Chrysanthemum.jpg [thumbnail_image] => Chrysanthemum.jpg [caption] => test [precedence] => 1 [published] => yes [thumb_width] => 210 [thumb_height] => 108 ) Array ( [id] => 2 [image] => Desert.jpg [thumbnail_image] => Desert.jpg [caption] => sssss [precedence] => 2 [published] => yes [thumb_width] => 210 [thumb_height] => 108 ) Array ( [id] => 3 [image] => Hydrangeas.jpg [thumbnail_image] => Hydrangeas.jpg [caption] => hhhh [precedence] => 0 [published] => yes [thumb_width] => 210 [thumb_height] => 108 )
  • edited November 2014
    so what we can do now ....i am waiting for ur nice reply its night time here i will be able to reach some where whats will be so now
  • edited November 2014
    What does this output?
    $gallery = fuel_model('photo_gallery'); foreach($gallery as $image): print_r($image->image_path); endforeach;
  • edited 4:15PM
    A PHP Error was encountered

    Severity: Warning

    Message: Invalid argument supplied for foreach()

    Filename: core/Loader.php(332) : eval()'d code

    Line Number: 4
  • edited November 2014
    yes not its giving the path of images ,i have three images
    $gallery = fuel_model('photo_gallery');
    //var_dump($gallery);


    //exit();
    foreach($gallery as $image):
    print_r($image->image_path);
    endforeach;
    and the out put is now as below:
    /gasification/assets/images/gallery/Chrysanthemum.jpg/gasification/assets/images/gallery/Desert.jpg/gasification/assets/images/gallery/Hydrangeas.jpg

    so for one image path it is
    /gasification/assets/images/gallery/Chrysanthemum.jpg
  • edited 4:15PM
    You many need to adjust the "get_image_path" method in the "Photo_gallery_item_model" record model to get it to match what you need. In addition, there is a GALLERY_DIR constant you may want to change to match the image folder.
  • edited 4:15PM
    i have shown the thumnails successfully....:)......now i want to open it in lightbox when clicked......can u guide 4 lightbox in fuel
  • edited 4:15PM
    You can use a normal javascript plugin for that like this one:
    http://lokeshdhakar.com/projects/lightbox2/

    You can place the javascript in the assets/js/ folder and the call it in your view file:

    <?=js('my_lightbox.js')?>
  • edited 4:15PM
    i have done this gallery section successfully ....it was all by the help from your side ....great admin and great support and great fuel
Sign In or Register to comment.