Easy way to optionally include extended properties

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
tombriggs
Regular
Posts: 24
Joined: Thu Aug 09, 2007 3:54 pm

Easy way to optionally include extended properties

Post 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
mad-manne
Regular
Posts: 42
Joined: Wed Jan 23, 2008 4:56 pm
Location: Marl, Germany
Contact:

Post 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.
Try not. Do or do not. There is no try. (YODA)
tombriggs
Regular
Posts: 24
Joined: Thu Aug 09, 2007 3:54 pm

Post 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:
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post 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.
Last edited by Don Chambers on Fri Feb 29, 2008 3:44 pm, edited 1 time in total.
=Don=
lordcoffee
Regular
Posts: 308
Joined: Tue Nov 29, 2005 10:22 pm
Location: Munich - Germany
Contact:

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Post 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.
=Don=
lordcoffee
Regular
Posts: 308
Joined: Tue Nov 29, 2005 10:22 pm
Location: Munich - Germany
Contact:

Post by lordcoffee »

Shame on me! :-)

Thanks a lot!
Post Reply