Jump to:

10930 Posts in 2613 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » Content outside $Layout

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1261 Views
  • richardus
    Avatar
    Community Member
    6 Posts

    Content outside $Layout Link to this post

    Hello,

    please help me. How Can I place content to template outside $Layout? I want place other content from structure.

    Thanks,

    Richard

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Content outside $Layout Link to this post

    Not sure if I'm understanding your problem, please elaborate.

    templates/Page.ss
    This should contain code that's on every page of your site (header, footer, main navigation). If you need to pull fields from the CMS of a specific page

    <% control Page(my-page) %>
    $Content
    <% end_control %>


    http://doc.silverstripe.org/doku.php?id=built-in-page-controls&s=page%20controls

  • richardus
    Avatar
    Community Member
    6 Posts

    Re: Content outside $Layout Link to this post

    Hello,

    I want place to outside $content tag other content (not the main content) eg. contact information so that was always displayed on each page.

    Thank You very much,

    Richard

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Content outside $Layout Link to this post

    So you have Contact Info that needs to go on every single page of your site.

    In the CMS, if it's for every page, I usually make a new tab on the Home page (other people may do it differently). I did this for my footer (See screenshot).

    HomePage.php

    class HomePage extends Page {
    static $db = array(
       'Footer' => 'HTMLText'
    );

    function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Footer', new HTMLEditorField('Footer', 'Content'));

          return $fields;
    }
    }

    Page.ss (templates/Page.ss) not templates/Layout/Page.ss

    .....
    <div id="content">
       $Layout
    </div>
    <div id="footer">
       <% control Page(home) %>
          $Footer
       <% end_control %>
    </div>
    .....

    Attached Files
  • UncleCheese
    Avatar
    4085 Posts

    Re: Content outside $Layout Link to this post

    That's the best way to do it is to put the field on your HomePage object. I'm not a big fan of control Page(home), though, because if the URLSegment ever changes, you're hosed. I usually write a function for it.

    return DataObject::get_one("HomePage")->ContactInfo;

    Also, if you're looking to have different content on every page, you can put that in your Page class. If you had the field ContactInfo in your $db array for Page, you could put $ContactInfo anywhere on your template -- within $Layout or outside of it.

    1261 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.