Forums / Setup & design / Possible to override embedded object template based on object's properties?

Possible to override embedded object template based on object's properties?

Author Message

Joel Hardi

Thursday 17 February 2005 11:04:35 am

Here's the problem:

I'd like to be able to embed both images and file links inside XML fields. Images should be displayed as block elements as in the default eZ Publish functionality -- wrapped in <div class="object-(align)"> tags. But embedded files I would like to display as inline, so that my users can just <a href="this is a normal link to a file">link to a file</a> in the normal flow of a sentence.

I know I can override the embed.tpl embed template so that images and files use different embed templates -- that's easy.

The problem is I need to override object.tpl (content/datatype/view/ezxmltags/object.tpl) -- the single template that determines how all objects are embedded in XML fields. But I need to override it based on the class, section or something of the <b>object being embedded</b> not the properties of the <b>object it's being embedded in</b> (which is article, for instance).

I want object.tpl to work one way for images, another for files.

Is there any way to do this? Or is there a workaround that would work?

I've run into this problem before but have always been able to work around it by doing an override on some combination of class, section and attribute_identifier, but that won't work this time since all of these objects are being embedded in the same attribute (body text) of the same class (article) in the same section.

Any ideas?

Arran Price

Thursday 17 February 2005 11:22:50 am

Can you just override to a new template which has additional logic in it?
So instead of using an override to determine the display method, use the template itself to do the more complex checking.
ie

{section show=one set of rules}
   display stuff
{/section}
{section show=another set of rules}
   another set of display stuff
{/section}

Joel Hardi

Thursday 17 February 2005 11:40:25 am

Thanks, that's what I've wound up doing! Here's the final template if anyone's interested. It changes to inline mode for files, but for everything else uses the default 3.5 object.tpl code:

{* displays as inline or block-level based on the embedded object''s class *}
{switch match=$object.contentclass_id}
{case match='12'}{* 

files display as inline

*}
{set-block scope=root variable=is_block}false{/set-block}
{content_view_gui view=$view object_parameters=$object_parameters attribute_parameters=$object_parameters content_object=$object}
{/case}
{case}{* 

everything else display as block using standard eZ object.tpl

*}

{let object_align='right'}
    {switch match=$object_parameters.align}
        {case match='left'}
            {set object_align='left'}
        {/case}
        {case match='right'}
            {set object_align='right'}
        {/case}
        {case match='center'}
            {set object_align='center'}
        {/case}
        {case/}
    {/switch}

    <div class="object-{$object_align}{section show=ne($classification|trim,'')} {$classification|wash}{/section}">
        {content_view_gui view=$view object_parameters=$object_parameters attribute_parameters=$object_parameters content_object=$object}
    </div>

{/let}

{*
Set variable to true if the object should be rendered as a block
tag. If it should be rendered as inline use false.
{set-block scope=root variable=is_block}true{/set-block}

*}
{/case}
{/switch}

Craig Hirsch

Monday 28 March 2005 8:50:32 am

Wow, this solved an identical problem that I was having. Thanks for sharing your solution.

--
chirsch{AT}gmail{d.t}com

Jonathan Dillon-Hayes

Monday 28 March 2005 12:09:20 pm

I'd like to second thanks. This was very helpful on a project I'm hacking on with the nearly identical problem.

Jonathan

---------
FireBright provides advanced eZ deployment with root access
http://www.FireBright.com/