0
Welcome Guest! Login
0 items Join Now

SOLVED Add ”noopener” tag for new window links in relevant Particles

    • Magh S.'s Avatar
    • Magh S.
    • Rocketeer
    • Posts: 50
    • Thanks: 0

    SOLVED Add ”noopener” tag for new window links in relevant Particles

    Posted 4 years 2 weeks ago
    • Hello,

      Some particles are for including links, e.g. Social particle, Simple menu etc. Is it possible to add support for the rel=”noopener” tag if any link is configured to open in a new window?
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13484
    • Web Designer/Developer

    Re: SOLVED Add ”noopener” tag for new window links in relevant Particles

    Posted 4 years 2 weeks ago
    • I'll pass it along as a suggestion but it's unlikely that we're going to go back through hundreds of particles to make that change. So, you will need to create particle overrides for where you need this and make the change yourself.

      To learn how to override a particle in Gantry 5 please see our documentation here http://docs.gantry.org/gantry5/tutorials/overriding-particle-settings#overriding-particle-source-files .



      Regards, Mark.
    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.
    • Magh S.'s Avatar
    • Magh S.
    • Rocketeer
    • Posts: 50
    • Thanks: 0

    Re: SOLVED Add ”noopener” tag for new window links in relevant Particles

    Posted 4 years 2 weeks ago
    • The problem is not the override but how to add the tag ONLY IF the link target is blank.

      e.g. this is the twig file's code from Simple menu (Aquatik). But more or less, such same code is found in other particles, e.g. social ones.
       <a target="{{ item.target|default('_blank') }}" href="{{ item.link|e }}" title="{{ item.title }}">{{ item.title|raw }}</a>

      A rel tag can be added
       <a target="{{ item.target|default('_blank') }}" href="{{ item.link|e }}" rel="noopener" title="{{ item.title }}">{{ item.title|raw }}</a>

      but then all links will have this attribute, not just the new window ones.
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13484
    • Web Designer/Developer

    Re: SOLVED Add ”noopener” tag for new window links in relevant Particles

    Posted 4 years 2 weeks ago
    • Just add a test for the field value.

      Regards, Mark.
    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.
    • Magh S.'s Avatar
    • Magh S.
    • Rocketeer
    • Posts: 50
    • Thanks: 0

    Re: SOLVED Add ”noopener” tag for new window links in relevant Particles

    Posted 4 years 2 weeks ago
    • Some of us aren't programmers, Mark. So... no idea what field testing is, let alone write it.

      In general, the "noopener" tag should be added by default for all new window links. It closes a security hole and has no impact on SEO. Editors like JCE have implemented it since a long time now. If for RocketTheme it is time-consuming to improve the security of these particles, at least a code fix could be offered so we can add that.
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13484
    • Web Designer/Developer

    Re: SOLVED Add ”noopener” tag for new window links in relevant Particles

    Posted 4 years 2 weeks ago
    • Ok, so let me describe what a test is..

      In rough english it would be:

      If condition
      .... do something
      else
      ... do something else
      endif

      If your case you said you only wanted to add the rel="noopener" if the target was a new window (i.e. "_blank")

      So in TWIG language you would write that as
      {% if item.target|default('_blank') == "_blank" %}
         rel="noopener"
      {% endif %}

      So that means that the code that you provided should be:
      <a target="{{ item.target|default('_blank') }}" href="{{ item.link|e }}" {% if item.target|default('_blank') == "_blank" %}rel="noopener"{% endif %} title="{{ item.title }}">{{ item.title|raw }}</a>


      Also, the comparison to an editor is not really applicable here since there is no ONE editor for particles - every particle had it's own code - so every particle would need to be changed to add this functionality for links. Also, the assertion that everyone will have the same requirement as you to add rel="noopener" to every link that opens in a new window may be incorrect. So the suggestion that I have actually made for future particles is that we just add a "rel" field into which you can key what you like as a user and it will be added to the link. In fact, we did already do something very similar for the Gantry 5 menu editor where you can add attributes to the link.

      I hope that now helps.

      Regards, Mark.
    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.
    • Magh S.'s Avatar
    • Magh S.
    • Rocketeer
    • Posts: 50
    • Thanks: 0

    Re: SOLVED Add ”noopener” tag for new window links in relevant Particles

    Posted 3 years 10 months ago
    • The 'rel' field proposal is brilliant!
      And solves a whole lot more.

      Thanks Mark.

Time to create page: 0.082 seconds