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

Ability to override Component partials (Cherry pick method) #41

Closed
daftspunk opened this issue Apr 28, 2014 · 1 comment
Closed

Ability to override Component partials (Cherry pick method) #41

daftspunk opened this issue Apr 28, 2014 · 1 comment

Comments

@daftspunk
Copy link
Member

Some Plugins can have many interconnecting partial references. This can become an issue when a theme wants to change a single partial in a component. At the moment the plugin's entire partial structure must be rebuilt in the theme up until the point the partial is used.

Concept one

Let's take the Plugin called Forum for example, with a component named Channel, it has these partials:

default.htm
pagination.htm
topics.htm
title.htm

And look at the code inside default.htm:

<div class="rainlab-forum">
    {% partial __SELF__ ~ "::title" %}

    {% partial __SELF__ ~ "::topics" %}

    {% partial __SELF__ ~ "::pagination" %}
</div>

Let's say a user wants to override the title partial only. As a component developer, I can predict this and make room for it. If I change the partial code to this:

{% partial "title" %}

By using this code instead, we will say:

  1. Look at the Theme for partials/title.htm
  2. If nothing found, look at each component used, find the one with partials/title.htm
  3. Render the result, or produce an error (Partial not found)

There is one problem with this scenario, the name "title" is too generic. It should be called "forum_channel_title" instead, but let's ignore that and keep it simple for now.

Concept two

But what if we don't want the partial to overriden by the theme, I like the idea of using short partial names. This can be possible by forcing the CMS to look at Components first, not the Theme.

{% partial @"pagination" %}

The @ symbol is responsible for this here. It will translate to ::pagination, when the component name is missing like this, all available components will be scanned. This is a "relaxed" approach.

However, to avoid conflicts with other components, a strict approach can be used, like so:

{% partial __SELF__ ~ "::pagination" %}

This is not as pretty, but it explicitly defines the component alias and will eliminate the possibility of another component used on a page or layout that also has a partial called pagination.

Concept three

Extending concept one, it can still be possible to override a component on the basis of it's alias.

Take this page code for example, the same component is used twice, with a separate alias, and separate config.

[channel myChannel1]
...
[channel myChannel2]
...
==
{% component 'myChannel1' %}
{% component 'myChannel2' %}

This is how we can override title.htm in this scenario, inside the theme /partials folder:

  • mychannel1\title.htm <== Custom partial for myChannel1 (Priorty 1)
  • mychannel2\title.htm <== Custom partial for myChannel2 (Priorty 1)
  • title.htm <== Custom partial for both (Priorty 2)

We can cherry pick the partial, based on the alias given to the component.

@daftspunk
Copy link
Member Author

Superseded by #44

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

No branches or pull requests

1 participant