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

Question: Partials with inline styling and/or scripting support ala content_for_header #723

Open
driekus77 opened this issue Nov 29, 2024 · 2 comments

Comments

@driekus77
Copy link

Is it possible to use Partials with inline styling and/or scripting?

Sort of a content_for_header feature (See https://shopify.dev/docs/api/liquid/objects/content_for_header)

Or even beter a ViewComponent structure (Like Angular):

   Views\Components\MyNewComponent
           MyNewComponent.html  
           MyNewComponent.css
           MyNewComponent.js

So you have to have a Placeholder where to put the inline css and js e.g. inside layout.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>{{ product_id }} - {{ product_title }} {{ product_type }}</title>
    <style>
        {{ 'styles.css' | inline_asset_content }} 
        
       {{ content_for_viewcomponents_stylesheet }}
    </style>
</head>
<body>
    {% viewcomponent 'MyNewComponent' %}

    <main role="main" id="MainContent">
        {% renderbody %}
    </main>

   <script>
       {{ content_for_viewcomponents_javascript }}
   </script>
</body>
</html>

Is the FluidViewEngine parser its extensibility sufficient to add above functionality?

Thanks in advance!

@sebastienros
Copy link
Owner

Yes. This is how "layout" and sections are implemented in the mvcc/view engine package.

This should be explained already in the readme, there are helpers to add commonly structured tags, it you can even replace the grammar in your project. I'll point you to specific examples later if you are still stuck.

@driekus77
Copy link
Author

Thanks for quick reply!

Its working now! But sections rendering only works in views not in partials?
My header.html partial didn't work with a:

{% section styles %}
...
{% endsection %}

When I move this section to a View the styling is oke.

Is it possible to use (render)section in combination with partials?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants