Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

insert variable inside an url

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Ganderik
Smarty n00b


Joined: 28 Jun 2012
Posts: 2

PostPosted: Thu Jun 28, 2012 10:40 am    Post subject: insert variable inside an url Reply with quote

Hi i am trying to do something that i thought was fairly simple, but aparently not.

I have assigned a variable:
Code:

{if $smarty.server.SERVER_ADDR == "IP address to server"}
   {assign var="linkLoc" value="Predefined IP adresse"}
{else}
   {assign var="linkLoc" value="Another predefined IP adresse"}
{/if}


Then i later (supposed to) use that variable to change the location the link should take me to
Code:

<img id="logoImage" alt="non pic" src="resources/images/pic.png" width="150" onclick="location.href='https://${linkLoc}/folder/index.php?m=welcome'" onmouseover="try {this.style.cursor='hand'} catch(e) {this.style.cursor='pointer'};"/>


But the output for the variable inside of the link, is only {$linkLoc}. What is wrong?
Back to top
View user's profile Send private message
ChrisFah
Smarty Pro


Joined: 02 Nov 2009
Posts: 159
Location: Traun, Austria

PostPosted: Thu Jun 28, 2012 11:53 am    Post subject: Reply with quote

Hi,

at first look, i see following :

Code:

<img id="logoImage" alt="non pic" src="resources/images/pic.png" width="150" onclick="location.href='https://[color=red]${linkLoc}[/color]/folder/index.php?m=welcome'" onmouseover="try [color=red]{this.style.cursor='hand'}[/color] catch(e) [color=red]{this.style.cursor='pointer'}[/color];"/>

Chang to: {$linkLoc} -> the $ not outside the braces
{ this.style.cursor='hand' } and { this.style.cursor='pointer' } -> a whitespace after and before the braces, else smarty will handle this js as a veriable.

Regards, Chris
Back to top
View user's profile Send private message
Ganderik
Smarty n00b


Joined: 28 Jun 2012
Posts: 2

PostPosted: Thu Jun 28, 2012 2:10 pm    Post subject: Reply with quote

Thanks for the reply. I think i fixed it my self by accident Surprised. But i did the same as you are telling. I removed the whole try catch and replaced it with a plain old:

Code:

onmouseover="this.style.cursor='pointer';"


have an excellent day.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP