SIlverstripe检查.ss文件中的页面名称

Mau*_*o74 2 templates silverstripe

我想检查模板.ss文件 - 页面名称或标题,以显示不同的图像.我想做那样的事情:

<% 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 %>
Run Code Online (Sandbox Code Playgroud)

上面的代码当然不起作用.我该怎么做?有没有更有效的方法呢?

非常感谢.
毛罗

ivo*_*oba 6

如果你想通过标题检查它使用$ Title(没有SiteConfig控制器)?

<% if $Title == 'video' %> 
   <img src="themes/blackcandy/images/image.jpg" /> 
<% else if $Title == 'bio' %> 
   <img src="themes/blackcandy/images/image1.jpg" />
<% end_if %>
Run Code Online (Sandbox Code Playgroud)

如果要检查PageType,请使用ClassName

<% if ClassName = PageType1 %>
    <img src="themes/blackcandy/images/image1.jpg" /> 
<% end_if %>
Run Code Online (Sandbox Code Playgroud)

如果您想通过Url检查UrlSegment(请参阅Clints answer)