wintercms / winter

Free, open-source, self-hosted CMS platform based on the Laravel PHP Framework.
https://wintercms.com
MIT License
1.38k stars 193 forks source link

Twig not recovered View::share() #630

Closed Dreanad closed 1 year ago

Dreanad commented 2 years ago

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

LukeTowers commented 2 years ago

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.

github-actions[bot] commented 1 year ago

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 wintercms@luketowers.ca.

LukeTowers commented 1 year ago

@bennothommo ping.

bennothommo commented 1 year ago

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

bennothommo commented 1 year ago

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.

LukeTowers commented 1 year ago

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