winter icon indicating copy to clipboard operation
winter copied to clipboard

Twig not recovered View::share()

Open Dreanad opened this issue 2 years ago • 1 comments

Winter CMS Build

1.2

PHP Version

8.1

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

Source : https://wintercms.com/docs/cms/content#content-global-variables

There seems to be a problem with twig to get the values in the View::share() function

The View::share() function return the good value but can not be recovered by twig on the front

Steps to replicate

In the boot function juste add View::share('site_name', 'Winter CMS');

and in the layout or any page / partial dump the "site_name" variable, its returning null

Workaround

No response

Dreanad avatar Aug 01 '22 09:08 Dreanad

See https://github.com/LukeTowers/oc-essentialvars-plugin/blob/master/Plugin.php#L38-L77 for how to handle this in a more robust fashion. @bennothommo @mjauvin do you think it's worth updating the docs for this? I'm not sure what the underlying issue is, I know I ran into it ages ago when I wrote that plugin though.

LukeTowers avatar Aug 02 '22 04:08 LukeTowers

This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at [email protected].

github-actions[bot] avatar Feb 01 '23 00:02 github-actions[bot]

@bennothommo ping.

LukeTowers avatar Jun 16 '23 23:06 LukeTowers

I'll have a look into why View::share doesn't work.

bennothommo avatar Jun 17 '23 02:06 bennothommo

Hi all,

Sorry for the extreme delay on this.

So it seems that View::share() is used exclusively for static content (ie. content blocks, placeholders, etc.) and is run through the Winter\Storm\Parse\Bracket bracket parser, which uses a single curly bracket (ie. {site_name}). It is not populated into the Twig variables.

I'm not sure if it should or not - I don't particularly see an issue for it to be available to the Twig environment as a default value that can be overridden by the page specifically defining a value, but happy to hear more thoughts on this. @LukeTowers @jaxwilko any thoughts?

I will note that this particular usage is defined on the Content Blocks page of the docs, so I think it was always intended to only be used there, but again, it could be extended out to Twig perhaps.

bennothommo avatar Sep 06 '23 07:09 bennothommo

I don't have a problem including them as default page variables.

LukeTowers avatar Sep 06 '23 20:09 LukeTowers