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 1 hour ago
leymannx
6,83342658
6,83342658
asked 3 hours ago
Basic
474
474
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.
1
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
28 mins ago
add a comment |
Use {{ node.getOwnerId() }}
<a href='/user/{{ node.getOwnerId() }}'>Your author name</a>
Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
– Basic
31 mins ago
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.
1
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
28 mins ago
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.
1
Thank you! {{ node.getOwnerId }} and {{ node.getOwner.label }} work well! By the way, {{ node.getOwner.label }} == {{ node.getOwner.getDisplayName }}
– Basic
28 mins ago
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.
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.
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
add a comment |
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
add a comment |
Use {{ node.getOwnerId() }}
<a href='/user/{{ node.getOwnerId() }}'>Your author name</a>
Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
– Basic
31 mins ago
add a comment |
Use {{ node.getOwnerId() }}
<a href='/user/{{ node.getOwnerId() }}'>Your author name</a>
Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
– Basic
31 mins ago
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>
answered 1 hour ago
Raj Ghai
1722
1722
Thank you! {{ node.getOwnerId() }} or {{ node.getOwnerId }} works!
– Basic
31 mins ago
add a comment |
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
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