Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes via package not reflected in Meta::toHtml() #55

Open
glenncoppens opened this issue Sep 7, 2023 · 2 comments
Open

Changes via package not reflected in Meta::toHtml() #55

glenncoppens opened this issue Sep 7, 2023 · 2 comments
Assignees
Labels
help wanted Extra attention is needed question Further information is requested
Milestone

Comments

@glenncoppens
Copy link

Describe the bug
I've registered 2 packages, "twitter" and "facebook" (og) via the MetaTagsServiceProvider (in boot method). Eg: when using $package = Meta::getPackage('facebook') and then modifying some og tags, these changes are not reflected in the html output (using Meta::toHtml() in the base view). I have to call Meta::replacePackage($package) explicitly in the controller to make the html render the updated tags.

Is this intended behaviour? For me the replacePackage call feels a bit counter intuitive and redundant because I already registered the package to be included by default (via config).

To Reproduce

  1. Register a default package (OpenGraph)
  2. Set some default values
  3. In a Controller, get the package, change eg the title
  4. check HTML as it will not reflect the updated title

Expected behavior
it should reflect changes immediately (without replace package)

Screenshots
/

Desktop (please complete the following information):

  • OS: MacOS
  • Browser FF
  • Version /
@butschster butschster added the question Further information is requested label Sep 10, 2023
@butschster butschster self-assigned this Sep 10, 2023
@butschster
Copy link
Owner

Hello, @glenncoppens,

Thank you for bringing this issue to my attention. You're correct: in the current design, when you register a package with predefined meta tags during the bootstrap period, these tags are directly registered in the Meta class. When you modify the package object afterwards, it doesn't automatically reflect the changes in the HTML output. For that, replacePackage has to be explicitly called.

This design choice was made to optimize for certain use-cases, but we understand that it may feel counterintuitive in your scenario.

Here are some additional points:

Workaround: For now, you would have to continue using replacePackage to see the updates reflected immediately.

Upcoming Changes: I am considering a redesign for package registration in the upcoming v3.0 release. Your feedback will be invaluable in shaping these changes.

If you want to try

Thank you for using our package and for your valuable feedback.

P.S.

If you have the time and interest, I invite you to help me in reshaping this logic. You can fork the repository, implement your approach, and create a PR to the 3.x branch. Your contributions will not only benefit your use case but also many other developers who might face a similar situation in the future.

@butschster butschster added the help wanted Extra attention is needed label Sep 10, 2023
@butschster butschster added this to the 3.0 milestone Sep 11, 2023
@Success-Guy
Copy link

I solved that type of issue by using
Meta::registerPackage() instead of toHtml() .

$og = new Butschster\Head\Packages\Entities\OpenGraphPackage('facebook');
$og->setType('website')
->setSiteName('mysite.com')
->setTitle($title)
->addImage($image)
->setDescription($description);
Meta::registerPackage($og);

With that you don't have to call toHtml() anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants