Overriding how an object name looks?

Author Message

eric l

Thursday 13 October 2005 6:52:57 pm

So this is only day two using ezpublish for me, so I apologize if my terminology is a little off.

I'm trying to set up recipes on my site, right now I have the following content classes:

Ingredient_Measure [Float, String] (Example: 0.5, Cup)
Ingredient_Type [String] (Example: Flour)
Ingredient [Ingredient_Measure, Ingredient_Type] (Example: 0.5 Cup Flour)

and Recipe, which has a variety of stuff but contains an ObjectRelations of Ingredients.

I made an override for node/view/full.tpl for the Recipe class, and I have it getting the content out of the $node mostly as expected. I'm using the attribute_view_gui call to display the ingredient list, which leads to a list of the ingredients with links to the nodes for those ingredients. But the names of the ingredients are as you would expect "0.50 Cup Flour" what I would like to do is override how that name is computed in order to display "1/2 Cup Flour"

How would I go about doing that? Or I suppose more to the point: Where is that name computed from the Ingredient class? As that is what I need to override.

Thanks!

eric l

Friday 14 October 2005 1:08:13 pm

To answer my own question...

When using attribute_view_gui to show an Object Relations list you can control how each of the objects being displayed in the list by overriding the /content/view/embed.tpl template for each Object Class in the relations list you want to change.

In my case I made:

design/plain/override/templates/ingredient_embed.tpl

which shows the amount of the ingredient in more normal recipe format of displaying fractions. (Anyone know if there is a handy function to get a fraction from a float so that I don't have to use that switch?)

------
{* Embedded Ingredient *}

{def $amount = $object.data_map.measure.content.data_map.amount.data_float}
{switch match=$amount}

{case match=0.125}
1/8
{/case}

{case match=0.25}
1/4
{/case}

{case match=0.5}
1/2
{/case}

{case match=0.75}
3/4
{/case}

{case match=1}
1
{/case}

{* Default to just showing the float. *}
{case}
{attribute_view_gui attribute=$object.data_map.measure.content.data_map.amount}
{/case}

{/switch}

{attribute_view_gui attribute=$object.data_map.measure.content.data_map.measure}

{* TODO change this to link to a list of all recipes using this type.*}
{attribute_view_gui attribute=$object.data_map.type.content.data_map.type}
------

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.