Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Link variable #161

Closed
bradfrost opened this issue Mar 29, 2014 · 8 comments
Closed

Link variable #161

bradfrost opened this issue Mar 29, 2014 · 8 comments
Assignees

Comments

@bradfrost
Copy link
Member

I'm really diving into using the link variable (http://patternlab.io/docs/data-link-variable.html), and am absolutely loving it.

One thing I'd like to be able to do is link to other patterns with _data.json. I set a lot of my patterns up like so:

<a href="{{ url }}">

and would love to be able to point that {{ url }} to other patterns. Is this possible?

@dmolsen
Copy link
Member

dmolsen commented Mar 29, 2014

@bradfrost -

This is a silly example but hope it makes the point. You want a molecule that has in it:

<a href="{{ url }}">Foo</a>

And when templates-blog includes the molecule you want url replaced with a link to pattern A. When templates-homepage includes the molecule you want url replace with a link to pattern B. Correct? So one var that gets changed to different patterns?

@bradfrost
Copy link
Member Author

Exaclty. So to further the example:

{{# foo }}
<a href="{{ url }}">Foo</a>
{{/ foo }}

In my templates-blog JSON file, I would do something like:

"foo" {
"url" : "link.pages-contact"
}

and in my templates-homepage JSON file

"foo" {
"url" : "link.pages-about"
}

@dmolsen
Copy link
Member

dmolsen commented Mar 29, 2014

@bradfrost -

I'm not hopeful I can implement this but I'll give it a shot.

@bradfrost
Copy link
Member Author

Just bumping this up, as I'm repeatedly running into this issue.

Wondering if there's a way to give a prefix to the data with "link" or something to make this happen. Or something like {{ link.url }}, which could be a flag when Mustache is being parsed. Sorry, I'm shooting in the dark here as I don't how things are compiled :(

@dmolsen
Copy link
Member

dmolsen commented Apr 19, 2014

@bradfrost -

Really fast hack at this is in dev. In your JSON you can do:

"foo": {
    "url" : "link.pages-about"
}

Where link.pages-about will be changed to the real path to the pattern. Let me know if this works for you.

@bradfrost
Copy link
Member Author

This works! Thanks for the amazing work. Wow this is so incredibly helpful.

@makeaweli
Copy link

Is this part of the current master?

@bradfrost
Copy link
Member Author

@makeaweli It sure is. You can learn more about it here

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

No branches or pull requests

3 participants