3212 Posts in 847 Topics by 809 members
| Go to End | Next > | |
| Author | Topic: | 599 Views |
-
<% if Link == "/" %> not work

8 March 2012 at 8:55am Last edited: 8 March 2012 9:13am
Hi all!
In template the following not work:
<% if Link == "/" %>
I get the following error when I do http://127.0.0.1/?flush=all:
Parse error: syntax error, unexpected '}' in C:\wamp\www\silverstripe-cache\.cache.themes.mysite.templates.Page.ss on line 406How should I put this comparison in the template?
Thanks,
Regards,
Jose -
Re: <% if Link == "/" %> not work

8 March 2012 at 9:13am
You shouldn't make a function in the controller and use that.
-
Re: <% if Link == "/" %> not work

8 March 2012 at 9:31am Last edited: 8 March 2012 9:34am
Hi Barry!
But, in my Navigation.ss
if I want to do the following:<ul>
<% control Menu(1) %>
<% if Link == "/" %>
<li><a href="$Link?locale=$locale" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a></li>
<% else %>
<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a></li>
<% end_if %>
<% end_control %>
</ul>Can't I do this?
How could I do this?
What am I doing wrong?
Thanks Barry!
Regards,
Jose -
Re: <% if Link == "/" %> not work

8 March 2012 at 11:27am Last edited: 8 March 2012 11:29am
Hi Jose,
What you are doing wrong is not reading the documentation, look here:
http://doc.silverstripe.org/sapphire/en/reference/advanced-templatesIn the section “If blocks” of this page you’ll find an explanation of how to use those if conditions, that are not as rich as PHP ones, for example: You should not include quotes around the value. Also, / will not work, I guess you should use home:
<% if Link == home %>Hope it helps,
Juan -
Re: <% if Link == "/" %> not work

8 March 2012 at 8:37pm Last edited: 8 March 2012 8:39pm
Hi Juanitou!
Yes, I read the documentation and I did that test ( <% if Link == home %> ), but it did not work. This condition does not occur, for this reason I tried the other type of condition:
<% if Link == "/" %>No one of the 2 ways works.
This way ( <% if Link == home %> ) does not produce any errors, but the condition is not true. Why?
I no longer know what to try.
Please some help.
Thanks,
Regards,Jose
-
Re: <% if Link == "/" %> not work

8 March 2012 at 9:29pm
Hi!
Don’t use Link:
<% if URLSegment == home %>
I should have spotted it before, sorry.
Hope it helps,
Juan -
Re: <% if Link == "/" %> not work

8 March 2012 at 9:43pm
Just to be clear... I should have given a slightly longer response...
You shouldn't [use an if for that]
[instead ]make a function in the controller
function LinkIsForwardSlash() {
return ($this->Link() == '/');
}and use that in the template. You will be able to use exact PHP to solve the problem and Debug::show() will work so you can figure it all out.
-
Re: <% if Link == "/" %> not work

9 March 2012 at 12:59am
Hi Juanitou!
Yes, Yes, Yes!!!!
It works!!!
The trick was to use URLSegment.
Thank you very much.
Regards,
Jose
| 599 Views | ||
| Go to Top | Next > |


