In the new design manager - I have a custom recent posts module for use on page templates that also a includes a link to the blog to see more posts. Is there anyway to use HubL to populate that link based on the ID chosen from the Blog selector?
I thought it might work in the same way as {{ page_by_id().url }} but it seems like the Blog selector produces the ID and nothing else.
There is a custom module "selector" field that outputs the selected blog ID:
You can use it in a recent post function by omitting the curly braces:
{# default token for my created blog field #}
{{ module.blog_field }}
{# token applied to recent posts function #}
{% set rec_posts = blog_recent_posts(module.blog_field, 5) %}
{% for rec_post in rec_posts %}
<div class="post-title">{{ rec_post.name }}</div>
{% endfor %}
I couldn't find any variables or functions that would give the url of a particular blog. If you only have one blog you can use:
{{ group.absolute_url }}
Otherwise you can get a little hacky and use the blog_all_posts_url fuction with a replace filter to remove "/all" from the url:
My solution is essentially the same as yours, only I didn't need to use regex because I played off of the "all posts" function. It still needs to use a replace filter, but you know what needs to be replaced so it is a simpler replace. Also, using the blog field, you would insert the blog id into the feed function and link function simultaneously anyways so there is no extra work.
I agree that there should be a function for generating a listing link from a blog ID, but there isn't. Maybe you should post something in the idea forum.
Jun 12, 20192:41 AM - bearbeitet Jun 12, 20194:06 AM
Stratege/Strategin | Diamond Partner
HubL for Blog URL based on ID
Yeah I've noticed this as well.
Basically every object type is obtainable using the content_by_id functionality, except for the blog root itself.
I was trying to do the same thing when I discovered this issue. Got recent blogs using a combination of the Blog field and blog_recent_posts function, but there's no way to get the blog listing URL from the Blog ID.
@alyssawilie if you're really desperate to automate it, and your blog is in a certain set format and urls are always at the same level, you can do something like this:
Jun 15, 20188:42 AM - bearbeitet Jun 15, 20188:44 AM
Teilnehmer/-in | Elite Partner
HubL for Blog URL based on ID
Sorry, that's not at all what I'm looking for. I want to get the root blog url based on the main blog ID you can set using one of the new field types in the new design manager's custom module. I don't want anything from the posts.