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

link variable not work #1

@ensk

Description

@ensk

when I try to create links to patterns as i did with patternlab + mustache {{ link.templates-mypattern }} fails, returns 0. I think it is because twig handle{{ link.templates }} as a simple variable and not like it should be

Activity

self-assigned this
on May 12, 2015
dmolsen

dmolsen commented on May 12, 2015

@dmolsen
Member

@ensk -

I'll look into this. Thanks for the heads up.

ensk

ensk commented on May 12, 2015

@ensk
Author

I think it's a problem with "-" because something similar happens when add a new value in data.json named my-var returns 0, but if I name my_var return the expected value. with the default values in data.json has a normal behavior

TxHawks

TxHawks commented on May 12, 2015

@TxHawks

It is probably the -. Since {{ }} in Twig is the print statement, anything inside it will be interpreted, so -s are treated as the minus operator. Basically, Twig is trying to subtract mypattern from link.templates.

A workaround would be to use the built-in attribute function like this:
{{ attribute(link, 'templates-mypattern') }}

This sort of works. The variable gets interpreted right, but the link points to one step too high in the directory hierarchy. E.g. ../../03-templates-00-mypattern/03-templates-00-mypattern.html instead of ../03-templates-00-mypattern/03-templates-00-mypattern.html

TxHawks

TxHawks commented on May 14, 2015

@TxHawks

@dmolsen -

Any reason why DataLinkExporter.php in patternlab-php-core has:

$value = "../../".$patternStoreData["pathDash"]."/".$patternStoreData["pathDash"].".html";

Rather than:

$value = "../".$patternStoreData["pathDash"]."/".$patternStoreData["pathDash"].".html";

../../ points links to / instead of /patterns/.

dmolsen

dmolsen commented on May 14, 2015

@dmolsen
Member

@ensk -

The issue is indeed related to the dash for the reasons @TxHawks notes. His solution is also the appropriate one. I'll leave this open until I can check out the separate issue he reported. I'm assuming it was just something stupid on my part.

TxHawks

TxHawks commented on May 20, 2015

@TxHawks

@dmolsen -

I fixed this by locally changing DataLinkExporter.php from:

$value = "../../".$patternStoreData["pathDash"]."/".$patternStoreData["pathDash"].".html";

to:

$value = "../".$patternStoreData["pathDash"]."/".$patternStoreData["pathDash"].".html";

Tried to test it with the Mustache edition, but couldn't install pattern-lab/edition-php-development#13.

Do you want a pull request on that?

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @dmolsen@TxHawks@ensk

      Issue actions

        link variable not work · Issue #1 · pattern-lab/edition-php-twig-standard