How to make author name hyperlinked to its profile in node template
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
add a comment |
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
add a comment |
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
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
8 theming
edited Dec 29 '18 at 7:26
leymannx
6,87442658
6,87442658
asked Dec 29 '18 at 5:48
Basic
575
575
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
To make that snippet a little bit more sustainable use the path()
function to build the link target. By that also path aliases (built with Pathauto for example) will be taken into account.
<div class="foobar">
<a href="{{ path('entity.user.canonical', {'user': node.getOwnerId}) }}">
<span>{{ node.getOwner.label }}</span>
</a>
</div>
2
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
Dec 29 '18 at 8:30
3
@Basic,getDisplayName
is not identical, it is a processed version of the name/label, see User::getDisplayName
– 4k4
Dec 29 '18 at 9:26
add a comment |
Use {{ node.getOwnerId() }}
.
<a href='/user/{{ node.getOwnerId() }}'>Your author name</a>
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
To make that snippet a little bit more sustainable use the path()
function to build the link target. By that also path aliases (built with Pathauto for example) will be taken into account.
<div class="foobar">
<a href="{{ path('entity.user.canonical', {'user': node.getOwnerId}) }}">
<span>{{ node.getOwner.label }}</span>
</a>
</div>
2
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
Dec 29 '18 at 8:30
3
@Basic,getDisplayName
is not identical, it is a processed version of the name/label, see User::getDisplayName
– 4k4
Dec 29 '18 at 9:26
add a comment |
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.
To make that snippet a little bit more sustainable use the path()
function to build the link target. By that also path aliases (built with Pathauto for example) will be taken into account.
<div class="foobar">
<a href="{{ path('entity.user.canonical', {'user': node.getOwnerId}) }}">
<span>{{ node.getOwner.label }}</span>
</a>
</div>
2
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
Dec 29 '18 at 8:30
3
@Basic,getDisplayName
is not identical, it is a processed version of the name/label, see User::getDisplayName
– 4k4
Dec 29 '18 at 9:26
add a comment |
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.
To make that snippet a little bit more sustainable use the path()
function to build the link target. By that also path aliases (built with Pathauto for example) will be taken into account.
<div class="foobar">
<a href="{{ path('entity.user.canonical', {'user': node.getOwnerId}) }}">
<span>{{ node.getOwner.label }}</span>
</a>
</div>
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.
To make that snippet a little bit more sustainable use the path()
function to build the link target. By that also path aliases (built with Pathauto for example) will be taken into account.
<div class="foobar">
<a href="{{ path('entity.user.canonical', {'user': node.getOwnerId}) }}">
<span>{{ node.getOwner.label }}</span>
</a>
</div>
edited Dec 30 '18 at 7:47
answered Dec 29 '18 at 7:25
leymannx
6,87442658
6,87442658
2
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
Dec 29 '18 at 8:30
3
@Basic,getDisplayName
is not identical, it is a processed version of the name/label, see User::getDisplayName
– 4k4
Dec 29 '18 at 9:26
add a comment |
2
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
Dec 29 '18 at 8:30
3
@Basic,getDisplayName
is not identical, it is a processed version of the name/label, see User::getDisplayName
– 4k4
Dec 29 '18 at 9:26
2
2
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
Dec 29 '18 at 8:30
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
Dec 29 '18 at 8:30
3
3
@Basic,
getDisplayName
is not identical, it is a processed version of the name/label, see User::getDisplayName– 4k4
Dec 29 '18 at 9:26
@Basic,
getDisplayName
is not identical, it is a processed version of the name/label, see User::getDisplayName– 4k4
Dec 29 '18 at 9:26
add a comment |
Use {{ node.getOwnerId() }}
.
<a href='/user/{{ node.getOwnerId() }}'>Your author name</a>
add a comment |
Use {{ node.getOwnerId() }}
.
<a href='/user/{{ node.getOwnerId() }}'>Your author name</a>
add a comment |
Use {{ node.getOwnerId() }}
.
<a href='/user/{{ node.getOwnerId() }}'>Your author name</a>
Use {{ node.getOwnerId() }}
.
<a href='/user/{{ node.getOwnerId() }}'>Your author name</a>
edited 2 days ago
kiamlaluno♦
79.5k9130248
79.5k9130248
answered Dec 29 '18 at 7:29
Raj Ghai
1902
1902
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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