Jump to content

Documentation for Template Variables? Please help me out!!


DReffects2

Recommended Posts

Hey guys,

So i am feeling like the biggest idiot right now. I am trying for 6 hours to output the frickin category name and link for a article listing in a block template for the news listing.

I cannot find any decent documentation anywhere and using print_r to outpur $record didn't help much, since I really do not see how I could output the array stuff since the information is not there (title for example, that is somehow being generated by $result->_title despite not being part of the array) or strange

 

IPS\cms\Records1 Object
(
    [displayTitle:protected] => 
    [displayContent:protected] => 
    [recordPage:protected] => 
    [customDisplayFields:protected] => Array
        (
        )

    [customValueFields:protected] => 
    [sharelinks:protected] => Array
        (
        )

    [container:protected] => IPS\cms\Categories1 Object
        (
            [_url:protected] => 
            [_catTitle:protected] => 
            [_stripTagsCatTitle:protected] => 
            [_catTitleLangKey:protected] => 
            [_lastCommentTime:protected] => 
            [_permsMashed:protected] => 
            [_updatePaths:protected] => 
            [_childrenResults:protected] => Array
                (
                )

            [_permissions:protected] => Array
                (
                    [perm_id] => 363
                    [perm_view] => 2,3,4,6,7
                    [perm_2] => 2,3,4,6,7
                    [perm_3] => 4,6
                    [perm_4] => 4,6
                    [perm_5] => 4,3,6,7
                    [perm_6] => 4,2,3,6,7
                    [perm_7] => 
                )

            [_originalPermissions:protected] => Array
                (
                    [perm_id] => 363
                    [perm_view] => 2,3,4,6,7
                    [perm_2] => 2,3,4,6,7
                    [perm_3] => 4,6
                    [perm_4] => 4,6
                    [perm_5] => 4,3,6,7
                    [perm_6] => 4,2,3,6,7
                    [perm_7] => 
                )

            [noCopyButton] => 
            [contentPostedIn:protected] => Array
                (
                )

            [_followData] => 
            [queued:protected] => 
            [_data:protected] => Array
                (
                    [id] => 12
                    [database_id] => 1
                    [name] => Amtliche Mitteilungen
                    [parent_id] => 0
                    [last_record_id] => 490
                    [last_record_date] => 1467958877
                    [last_record_member] => 89
                    [last_record_name] => 
                    [last_record_seo_name] => 
                    [position] => 2
                    [records] => 32
                    [has_perms] => 0
                    [show_records] => 1
                    [furl_name] => amtliche-mitteilungen
                    [meta_keywords] => 
                    [meta_description] => 
                    [forum_override] => 0
                    [forum_record] => 0
                    [forum_comments] => 0
                    [forum_delete] => 0
                    [forum_forum] => 1
                    [forum_prefix] => 
                    [forum_suffix] => 
                    [records_queued] => 0
                    [record_comments] => -3
                    [record_comments_queued] => 0
                    [page_title] => 
                    [full_path] => amtliche-mitteilungen
                    [last_title] => Halbseitige Sperrung der Staatsstraße
                    [last_seo_title] => halbseitige-sperrung-der-staatsstraße
                    [allow_rating] => 0
                    [fields] => 
                    [records_future] => 0
                    [record_reviews] => 0
                    [record_reviews_queued] => 0
                    [options] => 0
                    [template_listing] => 
                    [template_display] => 
                )

That's part of the result of {{print_r($record);}}

How would I now use

[name] => Amtliche Mitteilungen

in my template?

In 3.x I had no problems whatsoever designing those templates since print_r($result) provided everything I need, now it seems i have to be an expert in php to understand how the $records object is constructed. Trying a foreach for $records to ouput both key and value results in an exhausted memory limit all the time, even with this set to 1GB.

at this point i am willing to pay for a professional introduction into those frickin templates by some professional. The entire 4.x upgrade is a desaster. Templates are gone, block content does not work anymore, templates do not make ANY sense to me right now, all those helpful sidebars with a list of available variables and fields are gone. is this a bad dream?

:(:(:(:(

 

Link to comment
Share on other sites

  • 1 year later...

Sorry to dig this up again ;-)

While this particular answer was working for me I cannot make any sense of the "introduction to content items" article.

Where can I find a full list of all available methods?

At this very moment I am stuck with two problems:

  1. Trying to fetch information from a specific custom field in its raw form. (a URL field)
    |raw does not give me the desired result - it always returns a full html-tag with <a href.... attached to it. I just want the plain value.
  2. The database has a relational field with a linked record from another database. I'd like to access actual content of the linked record, not just the link-URL. something like $linked_database[fieldname] would be handy but I cannot figure out how to do that

Thanks :)

Link to comment
Share on other sites

7 minutes ago, DReffects2 said:

 

  1. Trying to fetch information from a specific custom field in its raw form. (a URL field)
    |raw does not give me the desired result - it always returns a full html-tag with <a href.... attached to it. I just want the plain value.

something like $record->field_XX with XX being the field ID will give you the unprocessed field content. 

7 minutes ago, DReffects2 said:
  1. The database has a relational field with a linked record from another database. I'd like to access actual content of the linked record, not just the link-URL. something like $linked_database[fieldname] would be handy but I cannot figure out how to do that

Not easily possible. Just the link and title are available in the database template. And that content comes from processing done in a theme template. You can retrieve everything from the linked record there, but then it will be used for all databases at the same time. 
 

Link to comment
Share on other sites

:)

Just now, opentype said:

something like $record->field_XX with XX being the field ID will give you the unprocessed field content.

Thank you mate! I was hoping this would be possible by using the actual field-name.

Just now, opentype said:

Not easily possible. Just the link and title are available in the database template. And that content comes from processing done in a theme template. You can retrieve everything from the linked record there, but then it will be used for all databases at the same time. 

Would it be possible to call this specific template (Seems to be cms -> front -> global -> basicRelationship) with the {template} tag instead? This would allow to create a custom template.

Link to comment
Share on other sites

39 minutes ago, opentype said:

I doubt it. But feel free to try and let us know. 

Hm I think it'd be possible if the $record variable would contain the actual database but that's not the case unfortunately :(

About $record->field_XX:

Do you know how to access a fields value with the field-name alone? I'd like to reuse my templates but the field id is different for every database of course but has the same name.

 

Link to comment
Share on other sites

3 minutes ago, Daniel F said:

You can use the customFieldDisplayByKey method for this.

While editing the field in the ACP, you'll see exactly what you need to use to get the value in the template 

Bildschirmfoto 2017-10-05 um 21.23.41.png

Hey Daniel,

thanks, but that only gives me a formatted value. If you have an URL-field this always returns a full <a href link instead of just the actual link.

Link to comment
Share on other sites

9 hours ago, DReffects2 said:

Hm I think it'd be possible if the $record variable would contain the actual database but that's not the case unfortunately :(

About $record->field_XX:

Do you know how to access a fields value with the field-name alone? I'd like to reuse my templates but the field id is different for every database of course but has the same name.

Another approach is to use the field settings, not the Pages template. In the field settings you can access the raw field content as $formValue and process and style it however you like. 

Link to comment
Share on other sites

8 hours ago, opentype said:

Another approach is to use the field settings, not the Pages template. In the field settings you can access the raw field content as $formValue and process and style it however you like. 

THANK YOU! I totally missed this one! :)

Link to comment
Share on other sites

So I tried with my limited PHP abilities to extract the actual field contents from a linked database. I did not want to modify the source code files to ensure upgrade compatibility so this is what I came up with:

Goals:

  • No modified source code
  • Not harming other relational fields

My solution:

  • The meta_keywords field for a custom database category is being used to trigger the modification
  • For the following example the String "#a#" (for array...) was entered into the Meta Keywords field of the linked database category. While I see that this might not be ideal it was the the one field I was able to access that did the least harm

image.png.d21686daf742d062d4279605e00c3eb0.png

The cms -> front -> global -> basicRelationship Template was modified like this:

{{foreach $items as $id => $item}}
	{{$trigger   = '#a#';}}
	{{$separator   = '||';}}

	{{if strpos($item->container()->meta_keywords, $trigger) !== false}}
		<a class="ipsPages_csv" href="{$item->url()}">{$item->_title}</a>

        {{for $i = 0; $i < 999; $i++}}
            {{$fieldname = "field_".$i;}}
            {{if $item->$fieldname != ""}}
          		{$separator}{$item->$fieldname}
            {{endif}}
        {{endfor}}

	{{else}}
	<a class="ipsPages_csv" href="{$item->url()}">{$item->_title}</a>
	{{endif}}
{{endforeach}}

This keeps all the regular linked fields from other categories intact since the else-part of the if-clause contains the original template output. What this does is create a sort of CSV formatted string. I've chosen || (two pipes) as a separator in the hopes that no one actually enters two pipes into the database... One can easily modify this of course...

The huge downside of this is that the for-loop goes from 1 to 999 for possible fields. If you have massive amounts of database fields you have to increase this value even further. If anyone knows how to pull a list of available fields please do tell. I also do not know how to retrieve the actual fieldnames and not just field_123...

Now moving on to any Record or Listing template. Here it gets really unprofessional...

<!-- extract the linked Record array -->
{{foreach explode("||",$record->customFieldDisplayByKey('bilderset')) as $fakearray}}
	<p>{$fakearray}</p>
{{endforeach}}

Now you can do as you please with all the

This outputs:

image.thumb.png.ab7bb2a58038f2afe863884116b801fe.png

Well.. hope this helps someone.

:)

Link to comment
Share on other sites

I have modified that Pages theme template as well. But I like to put all the output in there so I don’t have this FOR loop, which as you know is not very elegant. 

I don’t use a special trigger, but just check the database that is being called: {{if $item::$customDatabaseId == 3}}

Then I know what field are in that database and can output them directly, e.g. $item->record_image to add the record image to the link. 

This would only apply to database 3 in this case. All other cases would use the default output with just the text links.  

 

This works fine for my own sites. I still dislike that this is connected to the theme and cannot be done easily in the Pages templates themselves. So I can’t include this stuff in the Pages templates I sell on the Marketplace for example. :-( 

Link to comment
Share on other sites

I guess your solution will not work for me because the way I use the relation is different. I have a custom database called "image sets" - in there records with 5 upload fields, each representing a different image.

So i've got:

  • Icon 200x200
  • Header 1920x1080
  • Feature 300x300
  • etc.

For news articles a image set is assigned to the article. These images then fill certain spots in the layout. This is why i cannot output them in the basicRelationship but have to move them over to the actual Display Template.

Just found a bug with my code btw: since it's formatted so nice the array is pre- and appended by a lot of whitespaces.

Two ways around this: remove all whitespaces from the BasicRelationship template (does not look overseeable anymore) or work with

{{$substr = trim($bilderset[2]);}}

This of course can kill off some of your "real" whitespaces ;-)

All in all not really a good solution. This was way better in IPS3

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...