Linking to other Components Partial

I wonder a bit if I missunderstood the linking to partials.

If I just use {% partial “mypartial” %}, it’ll look in the active themes partial folder for mypartial.htm

If the path argument is “myfolder/mypartial”, it looks for the same file inside the folder “myfolder” within the themes partials.

So far so good.

Now I try to render other partials from inside my components default.htm partial.

Sure I could render partials wroted in the theme, but it seems wrong to have a themes dependencies from inside my plugins component. So ofc I try to store those additional component partials inside the components partial folder.

Which works fine… most of the time.

For ex:
Within the component “tagtree”, I have the default.htm which links to the tag.htm partial with this code:
{% partial “tagtree::tag” tag=tag %}

Works fine.

But if I would like to render this tag.htm partial from another component of the same plugin, it doesnt work. I wonder why. Is this not supported or did I miss something?

Or should I create a “partial” folder inside my plugin and put the partials there and link to it from the components partials … somehow?

Any support is welcome. Thanks a lot ^^

Does it work, when you give the full path to your partial? Something like this:

{% partial "~/plugins/acme/plugin_name/components/component_name/partial.htm" %}
1 Like

Hi maki,

thanks for the reply.

I tried it out, but having the ~ in the name creates an error:

An exception has been thrown during the rendering of a template ("Invalid file name: ~/plugins/mch/myplugin/components/tagtree/branches.htm. File names can contain only alphanumeric symbols, underscores, dashes and dots. Some examples of correct file names: page.htm, page, subdirectory/page").

I tried around a bit without the “~/” in the beginning, but couldnt get it to work.

Components should not reference partials from other components. Consider using Laravel views here, with the {% include %} Twig tag…

An example file plugins/acme/plugin_name/views/tag.htm can be included in Twig with:

{% include 'acme.plugin_name::tag' %}
1 Like

If you have a plugin with multiple components that are sharing partials, you can use the specific folder partials inside the components folder, and insert your shared partial there.
You can access them using {% partial '@tag' %}
with the following structure then: author/acme/components/partials/tag.htm


Thanks a lot you two!

Both solutions worked, but chris solution works perfect for my needs since I’ve multiple components and they should share some partials. So now, all components have the default.htm and one folder INSIDE the components folder with the shared partials.

That’s perfect.

Thanks a lot, problem solved ^^

Oh btw: I dont remember seeing this anywhere in the docu. Did I miss it?

Perhaps. Here is the docs link: Component Partials

1 Like