Page 1 of 1

Compressing templates from 3 to 1 using this {if} for images

Posted: Wed Apr 04, 2012 5:04 pm
by fearmydesign
In an effort to reduce the amount of templates that I create, I have created this {if} statement which seems to work in order to replace the top header image depending on which page it is on. Its working, but is there an easier/shorter/standard way to accomplish this same effect?

Here is my {if} calling/replacing the image according to the page its on:

Code: Select all

<div id="top-header-container">
     <div id="header-image">
           <img src="{if $page_alias == "house-cleaning-services-maryland"}uploads/images/static-banner/static_top_banner_01.jpg
             {elseif $page_alias == "cleaning-services-laurel-maryland"}uploads/images/static-banner/static_top_banner_02.jpg
             {elseif $page_alias == "house-cleaning-company-maryland"}uploads/images/static-banner/static_top_banner_03.jpg
             {else}uploads/images/static-banner/static_top_banner_01.jpg
           {/if}">
     </div>
</div>
Before this, I was creating 3 or 4 different templates and only replacing the img src file just to accomplish this same thing; to display a different header top image on different pages. Another words, I was creating different templates for each page :-\
I know, I know, but I didn't know how else to accomplish that.

Thank you for any feedback

Re: Compressing templates from 3 to 1 using this {if} for im

Posted: Wed Apr 04, 2012 6:42 pm
by Wishbone
Another option is to use GBFilePicker in {content_module} mode and allow the user to choose which image they want (or upload another) for any page... Have it default to some image if there is no file selected.

Re: Compressing templates from 3 to 1 using this {if} for im

Posted: Wed Apr 04, 2012 7:33 pm
by fearmydesign
Wishbone wrote:Another option is to use GBFilePicker in {content_module} mode and allow the user to choose which image they want (or upload another) for any page... Have it default to some image if there is no file selected.
Thank you, I will be sure to look into this option as well.

Re: Compressing templates from 3 to 1 using this {if} for im

Posted: Wed Apr 04, 2012 7:35 pm
by Dr.CSS
You can also use the page image in the Options tab...

Re: Compressing templates from 3 to 1 using this {if} for im

Posted: Wed Apr 04, 2012 7:48 pm
by fearmydesign
Dr.CSS wrote:You can also use the page image in the Options tab...
Thank you Dr. - my only question (because I have never used this section of the options tab) is; if I select a page image from the options tab, how would it place it on the page inside the div I want it to go into?

Code: Select all

<div id="top-header-container">
     <div id="header-image">
           <img src=" ? " >
     </div>
</div>
Thank you

Re: Compressing templates from 3 to 1 using this {if} for im

Posted: Thu Apr 05, 2012 1:21 am
by applejack
<img src="{$page_alias}.jpg">

Use a naming convention for your image files i.e. services.jpg

Re: Compressing templates from 3 to 1 using this {if} for im

Posted: Thu Apr 05, 2012 3:01 am
by Dr.CSS
Look under extensions > tags for {page_image}...

Re: Compressing templates from 3 to 1 using this {if} for im

Posted: Thu Apr 05, 2012 6:33 pm
by Rolf
Nothing to do with images though, but the multiple use of one template.
Might be fun to read or get some inspiration :) http://forum.cmsmadesimple.org/viewtopi ... 69#p270969

grtz. Rolf

Re: Compressing templates from 3 to 1 using this {if} for im

Posted: Thu Apr 05, 2012 7:52 pm
by Gregor
Rolf wrote:Nothing to do with images though, but the multiple use of one template.
Might be fun to read or get some inspiration :) http://forum.cmsmadesimple.org/viewtopi ... 69#p270969

grtz. Rolf
Nice answer Rolf :)

Gr. Gregor