aleksip / plugin-data-transform

Data Transform Plugin for Pattern Lab PHP
GNU General Public License v2.0
34 stars 10 forks source link

Add dummy drupal Url object #10

Closed charlotte17 closed 7 years ago

charlotte17 commented 7 years ago

If you want to do something like the following in your twig template, it isn't possible without an actual Url object. This is a very simple getter/setter of the Drupal's. It needs to be simple because we cannot expect to have a fully bootstrapped Drupal and there are too many dependencies on the verbatim class.

twig: <a href="{{ item.url }}"><i class="{{ item.url.option('attributes').class }}" ></i>{{ item.title }}</a>

data.json:

"items": [
          {
            "title": "Facebook",
            "url": {
              "Url()": {
                "url": "#",
                "options": {
                  "attributes": {
                    "class": "fa"
                  }
                }
              }
            }
          },
heddn commented 7 years ago

We should probably add some docs on how to use this and Attributes, otherwise it is an undocumented gem...

aleksip commented 7 years ago

I have just published v1.1.0 which contains your pull request and an updated README. Thanks again for your contribution!

heddn commented 7 years ago

Sweet. Thanks!

murphy1484 commented 7 years ago

How can I implement this with the link() function?

Below is what I have at the moment to add classes,

{{ link(item.title, item.url, { 'class':['nav-link']}) }}