How to make author name hyperlinked to its profile in node template












1














There is a variable {{ author_name }} in node.html.twig, it will print something like below:



<span>Your author name</span>


But I would like to print something like that:



<a href='/user/10'>Your author name</a>


How can I get this done in node.html.twig?










share|improve this question





























    1














    There is a variable {{ author_name }} in node.html.twig, it will print something like below:



    <span>Your author name</span>


    But I would like to print something like that:



    <a href='/user/10'>Your author name</a>


    How can I get this done in node.html.twig?










    share|improve this question



























      1












      1








      1







      There is a variable {{ author_name }} in node.html.twig, it will print something like below:



      <span>Your author name</span>


      But I would like to print something like that:



      <a href='/user/10'>Your author name</a>


      How can I get this done in node.html.twig?










      share|improve this question















      There is a variable {{ author_name }} in node.html.twig, it will print something like below:



      <span>Your author name</span>


      But I would like to print something like that:



      <a href='/user/10'>Your author name</a>


      How can I get this done in node.html.twig?







      8 theming






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago









      leymannx

      6,83342658




      6,83342658










      asked 3 hours ago









      Basic

      474




      474






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Normally {{ author_name }} already comes as renderable markup containing the linked author name. But there's also {{ node.getOwnerId }} (the author's user ID) and {{ node.getOwner.label }} (the author's user name) you could simply use to build the link yourself.



          <div class="foobar">
          <a href="/user/{{ node.getOwnerId }}">
          <span>{{ node.getOwner.label }}</span>
          </a>
          </div>


          Note you can easily inspect what variables are available for a template by installing the Devel sub-module Kint and then in your template print {{ kint() }}, flush cache and reload. You now will get all available variables pretty-printed to easily find out which ones you could use to solve your problem.






          share|improve this answer



















          • 1




            Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
            – Basic
            28 mins ago



















          1














          Use {{ node.getOwnerId() }}



          <a href='/user/{{ node.getOwnerId() }}'>Your author name</a>





          share|improve this answer





















          • Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
            – Basic
            31 mins ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "220"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f274446%2fhow-to-make-author-name-hyperlinked-to-its-profile-in-node-template%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Normally {{ author_name }} already comes as renderable markup containing the linked author name. But there's also {{ node.getOwnerId }} (the author's user ID) and {{ node.getOwner.label }} (the author's user name) you could simply use to build the link yourself.



          <div class="foobar">
          <a href="/user/{{ node.getOwnerId }}">
          <span>{{ node.getOwner.label }}</span>
          </a>
          </div>


          Note you can easily inspect what variables are available for a template by installing the Devel sub-module Kint and then in your template print {{ kint() }}, flush cache and reload. You now will get all available variables pretty-printed to easily find out which ones you could use to solve your problem.






          share|improve this answer



















          • 1




            Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
            – Basic
            28 mins ago
















          1














          Normally {{ author_name }} already comes as renderable markup containing the linked author name. But there's also {{ node.getOwnerId }} (the author's user ID) and {{ node.getOwner.label }} (the author's user name) you could simply use to build the link yourself.



          <div class="foobar">
          <a href="/user/{{ node.getOwnerId }}">
          <span>{{ node.getOwner.label }}</span>
          </a>
          </div>


          Note you can easily inspect what variables are available for a template by installing the Devel sub-module Kint and then in your template print {{ kint() }}, flush cache and reload. You now will get all available variables pretty-printed to easily find out which ones you could use to solve your problem.






          share|improve this answer



















          • 1




            Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
            – Basic
            28 mins ago














          1












          1








          1






          Normally {{ author_name }} already comes as renderable markup containing the linked author name. But there's also {{ node.getOwnerId }} (the author's user ID) and {{ node.getOwner.label }} (the author's user name) you could simply use to build the link yourself.



          <div class="foobar">
          <a href="/user/{{ node.getOwnerId }}">
          <span>{{ node.getOwner.label }}</span>
          </a>
          </div>


          Note you can easily inspect what variables are available for a template by installing the Devel sub-module Kint and then in your template print {{ kint() }}, flush cache and reload. You now will get all available variables pretty-printed to easily find out which ones you could use to solve your problem.






          share|improve this answer














          Normally {{ author_name }} already comes as renderable markup containing the linked author name. But there's also {{ node.getOwnerId }} (the author's user ID) and {{ node.getOwner.label }} (the author's user name) you could simply use to build the link yourself.



          <div class="foobar">
          <a href="/user/{{ node.getOwnerId }}">
          <span>{{ node.getOwner.label }}</span>
          </a>
          </div>


          Note you can easily inspect what variables are available for a template by installing the Devel sub-module Kint and then in your template print {{ kint() }}, flush cache and reload. You now will get all available variables pretty-printed to easily find out which ones you could use to solve your problem.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 59 mins ago

























          answered 1 hour ago









          leymannx

          6,83342658




          6,83342658








          • 1




            Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
            – Basic
            28 mins ago














          • 1




            Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
            – Basic
            28 mins ago








          1




          1




          Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
          – Basic
          28 mins ago




          Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
          – Basic
          28 mins ago













          1














          Use {{ node.getOwnerId() }}



          <a href='/user/{{ node.getOwnerId() }}'>Your author name</a>





          share|improve this answer





















          • Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
            – Basic
            31 mins ago
















          1














          Use {{ node.getOwnerId() }}



          <a href='/user/{{ node.getOwnerId() }}'>Your author name</a>





          share|improve this answer





















          • Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
            – Basic
            31 mins ago














          1












          1








          1






          Use {{ node.getOwnerId() }}



          <a href='/user/{{ node.getOwnerId() }}'>Your author name</a>





          share|improve this answer












          Use {{ node.getOwnerId() }}



          <a href='/user/{{ node.getOwnerId() }}'>Your author name</a>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          Raj Ghai

          1722




          1722












          • Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
            – Basic
            31 mins ago


















          • Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
            – Basic
            31 mins ago
















          Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
          – Basic
          31 mins ago




          Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
          – Basic
          31 mins ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Drupal Answers!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f274446%2fhow-to-make-author-name-hyperlinked-to-its-profile-in-node-template%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          サソリ

          広島県道265号伴広島線

          Setup Asymptote in Texstudio