Embeded file makes ezmatrix disappear

Author Message

Linh Vu

Monday 21 May 2007 11:13:10 pm

I'm using: ezp 3.8.8, php 4.4.7, mysql 4.1.15, apache 2.0.54

I have a Person object inserted in a Folder description (XML Block) with Embed view. The Person object has a Comment attribute (XML Block) and a Contact Information attribute (ezmatrix).

When the Comment attribute is blank or only contains normal text, everything is fine.

When the Comment attribute has a file inserted with Embed view, the Contact Information attribute is not output at all.

The full view of that Person works fine in either case.

This is the Person embed view template:

<div class="content-view-embed">
    <div class="class-person clearfix">

        <h2>{$object.name|wash} - {attribute_view_gui attribute=$object.data_map.job_title}</h2>
        {if $object.data_map.picture.has_content}
            <div class="attribute-image">
                {attribute_view_gui attribute=$object.data_map.picture.content.data_map.image alignment=left image_class=original}
            </div>
        {/if}

        <div class="attribute-long">
            {attribute_view_gui attribute=$object.data_map.comment}
        </div>

        <div class="attribute-matrix">
            <h3>{"Contact information"|i18n("design/base")}</h3>
            {attribute_view_gui attribute=$object.data_map.contact_information}
        </div>
    </div>

</div>

This is the File embed view template:

<div class="content-view-embed">
    <div class="class-folder">
    <h3 class="hide">{$object.name|wash}</h3>

    <div class="content-body">
{let attribute=$object.data_map.file}
{section show=$attribute.content}
<a href={concat("content/download/",$attribute.contentobject_id,"/",$attribute.id,"/file/",$attribute.content.original_filename)|ezroot}>{$attribute.content.original_filename|wash(xhtml)}</a> {$attribute.content.filesize|si(byte)}
{/section}
{/let}
     </div>
   </div>
</div>

And this is the ezmatrix view template (stock one that came with ezp):

{let matrix=$attribute.content}
<table>
<tr>
{section name=Rows loop=$matrix.rows.sequential}
    <td>
        {section name=Columns loop=$Rows:item.columns}
            {section show=0|eq($Rows:Columns:index)}
               {switch match=$attribute.contentclass_attribute_identifier}
               {case match='contact_information'}
                     <em>{$Rows:Columns:item}:</em>
               {/case}
               {case match='company_address'}
                     <em>{$Rows:Columns:item}:</em>
               {/case}
               {case}
               {/case}
               {/switch}
            {section-else}
               {$Rows:Columns:item|wash(xhtml)|autolink|nl2br}
            {/section}

        {delimiter}
        </td>
        <td>
        {/delimiter}
        {/section}
    </td>
    {delimiter}
    </tr>
    <tr>
    {/delimiter}
{/section}
</tr>
</table>
{/let}

It seems that when the embed file is there, the line {let matrix=$attribute.content} doesn't work at all, i.e $attribute doesn't exist for that template (I tried {$attribute|attribute(show,1)} and nothing came out).

I've done the usual object inspection, debug view, list of used templates and cache clearing, but I still haven't figured out what's going on. Help! :-)

If I had more time, I would write less code.

Linh Vu

Monday 04 June 2007 12:04:36 am

I got it figured out. The problem is that the $object variable appearing in both Person and File embed view templates are in the same scope so after printing out the comment in the Person template, the $object variable now contains the File (due to the File embed view template) instead of the original Person object.

To solve it, I simply add this at the top of the Person template:

{def $person=$object.data_map}

And use $person in place of $object.data_map from then on.

If I had more time, I would write less code.

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