Forums / Developer / Image link question

Image link question

Author Message

Niklas Gunnäs

Thursday 16 March 2006 12:23:23 am

I would like to fetch a value and use it to set with image to use. Is there a way to do this?

Exemple

<img src={"{$current_node.object.data_map.projektansvarig.contentclass_attribute.name|wash}.gif"|ezimage} alt="projectimage" align="absmiddle">

Kristof Coomans

Thursday 16 March 2006 2:18:01 am

This will work better:

<img src={concat($current_node.object.data_map.projektansvarig.contentclass_attribute.name|wash, ".gif")|ezimage} alt="projectimage" align="absmiddle">

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Niklas Gunnäs

Thursday 16 March 2006 4:45:45 am

Thanks a million, Kristof

Need some more help :-(

I use it in the following way

<img src={concat(status, $Child:item.object.data_map.status.contentclass_attribute.content.options[$:item.object.data_map.status.content[0]].name, ".gif")|ezimage} alt="projectimage" align="absmiddle"> {attribute_view_gui attribute=$Child:item.object.data_map.status}%

For value 00, 10 and 20 it works correct but from 30 to 100 it makes a jump to next value for exampel it will show image "status40.gif" and shows 30% next to the image, instead of status30.gif and 30%. Value 100 will not show at all.

Betsy Gamrat

Thursday 16 March 2006 5:47:42 am

I would check the class definition to see if one of the values is missing.

Niklas Gunnäs

Thursday 16 March 2006 5:59:16 am

Have checked a hundred times :-)

Gets the same error on diffrent classes

Kristof Coomans

Thursday 16 March 2006 7:12:33 am

In PHP, the class attribute options of the selection datatype are structured like this:

array(
    array( 'id' => 1, 'name' => 10 ),
    array( 'id' => 2, 'name' => 20 )
)

Now if you ever added options in an incorrect order and later corrected your mistake by reordering them, you can get this:

array(
    array( 'id' => 1, 'name' => 10 ),
    array( 'id' => 2, 'name' => 20 ),
    array( 'id' => 4, 'name' => 30 ),
    array( 'id' => 3, 'name' => 40 ),
)

So I think this should do it:

{def $statusAttrib=$Child:item.object.data_map.status}
{foreach $statusAttrib.contentclass_attribute.content.options as $classAttribOption}
{if $classAttribOption.id|eq(statusAttrib.content[0])}
<img src={concat(status, $classAttribOption.name, ".gif")|ezimage} alt="projectimage" align="absmiddle">&nbsp;{attribute_view_gui attribute=$statusAttrib}%
{/if}
{/foreach}
{undef $statusAttrib}

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Kristof Coomans

Monday 20 March 2006 12:02:01 pm

There was a little error in my previous template code. This should work:

{def $statusAttrib=$Child:item.object.data_map.status}
{foreach $statusAttrib.contentclass_attribute.content.options as $classAttribOption}
{if $classAttribOption.id|eq($statusAttrib.content[0])}
<img src={concat(status, $classAttribOption.name, ".gif")|ezimage} alt="projectimage" align="absmiddle">&nbsp;{$classAttribOption.name}%
{/if}
{/foreach}
{undef $statusAttrib}

And if your attribute is a multiple selection (works for single selection too):

{def $statusAttrib=$Child:item.object.data_map.status}
{foreach $statusAttrib.contentclass_attribute.content.options as $classAttribOption}
{if $statusAttrib.content|contains($classAttribOption.id)}
<img src={concat(status, $classAttribOption.name, ".gif")|ezimage} alt="projectimage" align="absmiddle">&nbsp;{$classAttribOption.name}%
{/if}
{/foreach}
{undef $statusAttrib}

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Niklas Gunnäs

Monday 20 March 2006 3:20:23 pm

It works, It works :-)

Dont know how to thank you.

If you ever comes to Stockholm I will buy you a very, very large beer :-)

Niklas
www.infos.se