17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1296 Views |
-
Conditionally inserting image

17 October 2007 at 10:12pm
Hello,
I would like to conditionally insert an image into Page.ss based on the value of $URLSegment and the presence of the image file:
First problem:
I am trying to generate the HTML to display the image and I have inserted the following code into Page.ss.<img class="center" src="assets/images/$URLSegment.jpg" alt="$Title" width="520" />
However, $URLSegment and .jpg is replaced with blank, ie. src=""assets/images/"
Second problem:
How do I detect the existence of this file in Page.ss so as to only insert the relevant HTML if the file exists?Cheers,
Gary
-
Re: Conditionally inserting image

19 October 2007 at 9:24pm
Hello,
To resolve this issue I inserted $URLSegment inside curly brackets ('{$URLSegment}').
I hope this helps.
Cheers,
Gary
-
Re: Conditionally inserting image

22 October 2007 at 9:16pm Last edited: 22 October 2007 9:17pm
Optionally, you could make a new function called ImagePath() on your class and use $ImagePath in the template, instead. This would automatically find the relative path, like assets/images/$URLSegment, so you just need to insert <img src="$ImagePath" alt="My image" /> - this avoids the problem of having curly braces in your nice templates.
function ImagePath() {
return 'assets/images/' . $this->URLSegment . '.jpg';
}<% if ImagePath %>
<img src="$ImagePath" alt="My image" />
<% end_if %>Cheers,
Sean -
Re: Conditionally inserting image

23 October 2007 at 10:13am
Thanks Sean - I might just try that.
Initially, I wasn't sure if I could pass a variable back from a function. I have been plugging away at the templating engine at the weekend and have made some breakthroughs - thanks to your support!
Many thanks,
Gary
| 1296 Views | ||
|
Page:
1
|
Go to Top |


