<unit relativeTo="...">: Equivalent in PHP code?

Hi,

I'm still struggling with templates. It seems that this doesn't work because pk_normdaten_type is a list (see other discussion):

{{{
<unit relativeTo="ca_entities.pk_normdaten" delimiter="<hr/>">
   URL: ^ca_entities.pk_normdaten.pk_normdaten_url<br/>
   Type: ^ca_entities.pk_normdaten.pk_normdaten_type
</unit>
}}}

I'd like to use PHP code instead but can't work out how to do it. What I came up with so far is the following:

$url_list  = $t_item->get("ca_entities.pk_normdaten.pk_normdaten_url",  array('returnAsArray' => true));
$type_list = $t_item->get("ca_entities.pk_normdaten.pk_normdaten_type", array('returnAsArray' => true));

The problem is: pk_normdaten_type is optional in my data model. If I have two instances of pk_normdaten and in of them pk_normdaten_type doesn't have a value then $type_list only has one entry and I don't know if that value belongs to the first or the second instance of pk_normdaten. Is there a better way to do this in PHP?

Thanks in advance, Martin

Comments

  • I think I found the solution. My original problem was that I couldn't use

    {{{
    <unit relativeTo="ca_entities.pk_normdaten" delimiter="<hr/>">
       URL: ^ca_entities.pk_normdaten.pk_normdaten_url<br/>
       Type: ^ca_entities.pk_normdaten.pk_normdaten_type
    </unit>
    }}}
    

    because it doesn't print the values for ca_entities.pk_normdaten.pk_normdaten_type (which is of data type list).

    Surprisingly this works:

    <?php
    print $t_item->getWithTemplate('<unit relativeTo="ca_entities.pk_normdaten" delimiter="<hr/>">
       URL: ^ca_entities.pk_normdaten.pk_normdaten_url<br/>
       Type: ^ca_entities.pk_normdaten.pk_normdaten_type
    </unit>');
    ?>
    

    Is this a bug?

  • Well it depends upon where you're doing this. The template needs to be evaluated relative to an entity. Depending upon which template you're sticking this in it may not be evaluated relative to what you think it is. Also, what version of CA are you doing this in? There have been a lot of changes over the past few years.

  • I put this in themes/default/views/Details/ca_entities_default_html.php. I'm using pawtucket2-1.7.11. The providence version is older (and some of the data has been saved years ago).

  • That is odd then. The two should be equivalent in that case.

  • edited July 10

    Actually... can you check the list items and make sure their "access" value is set to "public"? I tested this with 1.7.11 and the templating system is working as it should. But if the list items you're trying to output are not public, they will be suppressed when output in the template. If you output them using PHP code, access checks aren't performed unless you explicitly pass a list of access values to filter by using the checkAccess option on getWithTemplate(). So my statement that the two method are equivalent isn't quite true. Access enforcement is different.

  • You're right, access of the list items was set to false. I didn't configure the list and i didn't realize that list items have an access value. If I had tested it with some other list I might have noticed, though. :-/

    Thanks for testing for me and the feedback!

    Kind regards, Martin

Sign In or Register to comment.