3212 Posts in 847 Topics by 809 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 415 Views |
-
Check page name in .ss file

11 July 2012 at 9:27am Last edited: 11 July 2012 10:23am
Hi all, I'm new to Silverstipe so be patient please if the question has a very easy answer
I want to check β in the template β the page name or title in order to show a different image. I'd like to do something like that:
<% if $SiteConfig.Title == 'video' %>
<img src="themes/blackcandy/images/image.jpg" />
<% else if $SiteConfig.Title == 'bio' %>
<img src="themes/blackcandy/images/image1.jpg" />
...
...<% end_if %>
How do I do it? Is there a more efficient way of doing it?
Thanks a lot.
Mauro -
Re: Check page name in .ss file

11 July 2012 at 1:07pm
Which version of SilverStripe are you using?
Typically this would be something you accomplish in the controller. Namely write a controller method that either returns the title of the page, or rather write a controller method that returns the path to the image (and let the controller method go through the possibilities).
That said, it is reasonably easy to add attributes to pages that would allow you to specify say an image uri to act as the thumbnail for that page or something too.
-
Re: Check page name in .ss file

11 July 2012 at 10:27pm
Hi Mauro74,
If you just want to check against a page title, you should not use SiteConfig, rather just (note that the $ sign is not used in if and controls)
<% if Title == 'video' %>
Page title is: $Title
<img src="themes/blackcandy/images/image.jpg" />
<% else if Title == 'bio' %>
Page title is: $Title
<img src="themes/blackcandy/images/image1.jpg" />
<% end_if %>You can also add a field for each page, allowing the admin to specify a image in the backend for each page.
See the tutorials: doc.silverstripe.org -
Re: Check page name in .ss file

12 July 2012 at 6:36am
Note that different SilverStripe versions will have different syntax for comparisons in the template markup.
| 415 Views | ||
|
Page:
1
|
Go to Top |


