eZ Community » Forums » eZ Publish 5 Platform » Print related object with template...
expandshrink

Print related object with template w/o controller?

Print related object with template w/o controller?

Tuesday 30 April 2013 10:08:16 am - 19 replies

I'm using two Object relation fields to link to two different objects' locations from my full location view template. At least that's my endgoal, I haven't figured out how to get there yet.

Is there any way to accomplish this without having to create a controller for it? It seems to me like making a controller only to output a link is extremely overkill. The term subcontroller was thrown my way, perhaps that is the/a less overheady way to go?

Also, how is the easiest way to find the object IDs of the related objects? I'm currently outputting them like this: {{ content.fields.link_prices_order[location.contentInfo.mainLanguageCode].destinationContentId }}

But that is silly. Hoping for some much needed insight here. happy.gif Emoticon

Tuesday 30 April 2013 11:52:56 am

Jérôme would answer better than I do, but one of his recent posts on the forums might interest you: http://share.ez.no/forums/ez-publish-5-platform/customized-viewcontroller#comment79997.

Tuesday 30 April 2013 12:04:50 pm

I could walk over to Kristian's desk and check if he has had a chance to look at it yet, but again I think it looks like a lot of work to accomplish little. I want to be able to do most of this in templates, really, but I realize that some helper functions may not exist yet.

I've managed to get here:

{{ render(controller('ez_content:viewLocation', {
    'locationId': content.fields.link_prices_order[location.contentInfo.mainLanguageCode].destinationContentId,
    'viewType': 'link'
})) }}

... but what I currently have access to in my template, isn't the locationId, but the contentId. ez_content:viewContent + contentId doesn't seem to be working.

I'm also struggling with passing arguments into the view. Is it even possible using this type of "node_view_gui"?

Modified on Tuesday 30 April 2013 12:05:18 pm by Hein Haraldson Berg

Tuesday 30 April 2013 2:45:11 pm

This is where I'm at now:

{{ render(controller('ez_content:viewContent', {
    contentId: myContentId,
    viewType: 'link',
    params: {
        objectParameters: {}
    }
})) }}

For some reason, I have to provide params.objectParameters – but only for the first render statement in the template. Else I get one of those nasty Symfony error pages.

And still, I'm getting no output. Thought it might have been due to a lacking override statement;

parameters:
    ezsettings.productsites.location_view:
        full:
            product:
                template: KTQProductSitesBundle:full:product.html.twig
                match:
                    Identifier\ContentType: product
        link:
            any:
                template: KTQProductSitesBundle:particles:link.html.twig
                    match:
                        Identifier\Section: standard

I added a similar link.any.template etc. below parameters.ezsettings.productsites.content_view, but had no luck in doing so. 

Any help appreciated! happy.gif Emoticon

Modified on Tuesday 30 April 2013 2:46:06 pm by Hein Haraldson Berg

Tuesday 30 April 2013 3:58:12 pm

Hello

Indeed, you need to have your template selection rule under content_view, which was broken some weeks ago... It has been fixed recently (I'd say around february), so you'll need to update your ezpublish sources to get this working (will be in 5.1 and is in 2013.4).

As for how you define your template selection rules, this is a bad practice to do this under parameters. You should do this as explained here.

Tuesday 30 April 2013 4:13:49 pm

Thanks for the information, Jérôme. Will try to update.

But why on earth would I want such bundle-specific rules in ezpublish.yml, in /ezpublish/config(?) ?

Modified on Tuesday 30 April 2013 4:14:08 pm by Hein Haraldson Berg

Tuesday 30 April 2013 4:18:04 pm

Because these semantic settings are correctly validated and merged...

You can still import your bundle settings (if it's in a bundle) from ezpublish.yml.

Tuesday 30 April 2013 4:25:50 pm

Are there any docs on how to upgrade eZPublish 5 -> newer eZPublish 5, by the way?

php composer.phar update doesn't seem to be doing that.

Tuesday 30 April 2013 4:32:16 pm

I consider these override rules "bundle settings". Are you saying that all I need to do, is to import it into the global ezpublish.yml? (What's the point?)

My brain is quite pragmatic when it comes to stuff like this, and needs to understand why – being told "that's the way it should be" doesn't help one bit.

Tuesday 30 April 2013 4:49:04 pm

Quote from Hein Haraldson Berg :

I consider these override rules "bundle settings". Are you saying that all I need to do, is to import it into the global ezpublish.yml? (What's the point?)

The point, as I said above, is that your settings will be validated by the config parser and correctly merged with group/global/default settings. What you do will work, but group settings won't be correctly merged into your siteaccess settings for instance.

Tuesday 30 April 2013 8:03:53 pm

Just come over to my desk Hein and I will help you do the upgrade! I have not made our composer setup ready for version upgrades on eZ core happy.gif Emoticon

Thursday 02 May 2013 9:56:07 am

Replaced my vendor folder with the latest one available, 2013.4. Tried doing the same with ezpublish_legacy, but that was a tad trickier.

Anyway, I get the following error message when running the forementioned template code:

An exception has been thrown during the rendering of a template ("None of the chained routers were able to generate route: Route '' not found" )

I don't understand how routes are relevant here? I'm not trying to access this on some special predefined URL, but via a template.

Modified on Thursday 02 May 2013 9:56:46 am by Hein Haraldson Berg

Thursday 02 May 2013 10:36:56 am

I get this same error with the new way of doing overrides, so I'm fresb out of theories here...

Thursday 02 May 2013 10:59:09 am

Jérôme: Say I put my override rules in ezpublish.yml in my bundle.

How would I go about loading those? I've tried loading it via PHP, DependencyInjection/KTQProductSitesExtension.php, with no luck.

Was thinking about importing the settings from the global ezpublish.yml, but I'm not sure about the format, and how to refer to bundle files.

  1. How would my bundle-specific ezpublish.yml look – would I repeat the full hierarchy, or start on the level where the import statement in the global ezpublish.yml will be?
  2. Is there any naming convention that makes referring to bundle setting files simpler?

Thursday 02 May 2013 11:16:30 am

 

Quote from Hein Haraldson Berg :

How would I go about loading those? I've tried loading it via PHP, DependencyInjection/KTQProductSitesExtension.php, with no luck.

That's indeed not the right way to do. You need to import your file from your main ezpublish.yml:

# Place this at the top of your main ezpublish.yml
# You can add as many imports as you like
imports:
    - { resource: @MyBundle/Resources/config/template_rules.yml }
Quote from Hein Haraldson Berg :

How would my bundle-specific ezpublish.yml look – would I repeat the full hierarchy, or start on the level where the import statement in the global ezpublish.yml will be?

Yes, you need to repeat the hierarchy. The resulted array will be merged into the main one.

An alternative would be to do this in PHP by programmatically prepend configuration in your DI extension (see Symfony doc on this). In this case you can of course load configuration files...

Thursday 02 May 2013 12:29:13 pm

Thanks a lot, settings successfully moved. happy.gif Emoticon

This override statement makes my site crash, though:

ezpublish:
    system:
        productsite:
            content_view:
                link:
                    any:
                        template: KTQProductSitesBundle:particles:link.html.twig
                        match:
                            Identifier\Section: standard

This is after I upgraded my vendor folder. My View\Provider\Content\Configured isn't empty anymore, so it should work? Any idea why it doesn't?

Modified on Thursday 02 May 2013 12:43:21 pm by Hein Haraldson Berg

Thursday 02 May 2013 1:59:51 pm

Quote from Hein Haraldson Berg :

This override statement makes my site crash, though

Difficult to help without further description... "My site crash" is not a valid description for an issue blunk.gif Emoticon. I need the exception, the stack trace eventually (don't forget to run in dev mode, with index_dev.php, to get the full stack trace)

Thursday 02 May 2013 2:10:01 pm

Nothing to see here...

Modified on Thursday 02 May 2013 2:25:59 pm by Hein Haraldson Berg

Thursday 02 May 2013 2:17:30 pm

Please don't throw your log this way... What I asked you for is the exception you have with its stack trace, not your entire log.

Thank you.

Thursday 02 May 2013 2:44:06 pm

Solved by upgrading to 2013.4 and fixing my template, which used the location variable, which of course isn't available when working with viewContent. happy.gif Emoticon

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from