Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Themes /

Discuss SilverStripe Themes.

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

Using $Up or $Top in an include file


Go to End


2 Posts   761 Views

Avatar
Vix

Community Member, 60 Posts

20 October 2016 at 6:28pm

I have a fairly complex theme set up and for the most part I can use include files to add in the code for that part of the template. For example I have:

<% if ContentPanels %> 
    <% loop ContentPanels %>

    
      <% if PanelLayout = Text Block %>
        
        <% include TextBlocks %>       
      
      <% else_if PanelLayout = Image and Text %> 
        
        <% include ImageGrid %>     
etc...

However one of these layouts needs to access the $Top which does not work in an include file. Does anyone know of a work around for this, so that I am not repeating the same chunk of code on different page templates?

Avatar
Michael J James

Community Member, 8 Posts

23 December 2016 at 3:35am

Edited: 16/02/2017 12:13am

Hi @Vix,

You can add arguments into a include

<% loop ContentPanels %>

        <% if PanelLayout = Text Block %>

              <% include TextBlocks Top=$Top %>       

        <% else_if PanelLayout = Image and Text %> 

              <% include ImageGrid Top=$Top %>  

        <% end_if %>

<% end_loop %>

Documented Here:
https://docs.silverstripe.org/en/3.4/developer_guides/templates/syntax/#includes

Thanks
Michael