Page 1 of 1

Easy way to optionally include extended properties

Posted: Wed Feb 27, 2008 11:24 pm
by tombriggs
I have a handful of extended properties configured. I'd like to include them, along with some pre-defined text, in my posts only when the ep's are actually specified.

For example, say I have a property named ProductName. I'd like to have:

Name of this product: <product name>

Appear in my posts, but only when a product name is actually defined in the extended properties. (Product name is a completely arbitrary example... I'm not actually dealing with products.)

Is there an easy way to do this directly in the template or will I need to write a plugin to do this? If I do need to write a plugin can anyone suggest a good one to copy as a starting point?

Thanks
-Tom

Posted: Thu Feb 28, 2008 12:13 am
by mad-manne
Hi Tom,
yes there is an easy way, given that you know how to "address" the variables within the template.

Just wrap your line into an if-statement, so that you end up with something like this:

Code: Select all

{if $name_of_product != ""}Name of this product: {$name_of_product}{/if}
To find out more about what can be done in smarty-templates, have a look at their documentation :wink:

Hope this helps,
Manfred.

Posted: Thu Feb 28, 2008 12:21 am
by tombriggs
Ahh thanks, that's perfect.

I didn't realize that the Smarty templates were a separate project of their own... no wonder I couldn't find any documentation on this site about them. :oops:

Posted: Thu Feb 28, 2008 12:30 am
by Don Chambers

Code: Select all

{if $entry.properties.ep_ProductName}
  <span class="product_name">Product Name: {$entry.properties.ep_ProductName}</span>
{/if}
It can be a <p>, <div>, or whatever tag you want (or none at all). Ultimately, this is going to go into an entries.tpl file. Your template may, or may not, have a custom version of this file.

If it does not, you need to first copy that file from /templates/default to templates/yourtemplatefolder. The only remaining issue is where you want the text to appear relative to the rest of the entry.

EDIT: an equal (=) sign was missing between "class" and "product_name" when this message was originally posted. Corrected 2/29/2008.

Posted: Fri Feb 29, 2008 2:47 pm
by lordcoffee
Hi!

I'm trying to add a download field to my entries. I've put this code inside the entries.tpl and the text: Download file: "bla blubb" apears if I enter "bla blubb" in the custom field. Now I've tried to style this span and nothing happens. When I use the "css-viewer" it does not recognise the class. Any Ideas?

Code: Select all

{if $entry.properties.ep_downloads}
<span class"mydownloads">Download file: {$entry.properties.ep_downloads}</span>
{/if}

Code: Select all

.mydownloads {
color:red;
background-color:#FFCCCC;
border-top:3px solid #FFCC99;
border-bottom:3px solid #FFCC99;
}
Image

Thanks , Lordcoffee

Posted: Fri Feb 29, 2008 3:08 pm
by garvinhicking
Hi!

Did you check the rest of your HTML for validity? Try adding "!important" to your styles? The span should be there.

Regards,
Garvin

Posted: Fri Feb 29, 2008 3:43 pm
by Don Chambers
lordcoffee wrote:Hi!

I'm trying to add a download field to my entries. I've put this code inside the entries.tpl and the text: Download file: "bla blubb" apears if I enter "bla blubb" in the custom field. Now I've tried to style this span and nothing happens. When I use the "css-viewer" it does not recognise the class. Any Ideas?

Code: Select all

{if $entry.properties.ep_downloads}
<span class"mydownloads">Download file: {$entry.properties.ep_downloads}</span>
{/if}

Code: Select all

.mydownloads {
color:red;
background-color:#FFCCCC;
border-top:3px solid #FFCC99;
border-bottom:3px solid #FFCC99;
}

Thanks , Lordcoffee
Error in my original code... needs to be class="whatever".... note the missing equal sign. I've corrected the original post, but the equal sign was missing in both my original post as well as your quote.

Posted: Fri Feb 29, 2008 3:52 pm
by lordcoffee
Shame on me! :-)

Thanks a lot!