Display all Ghost tags - ghost

I would like to add all my tags to a footer section. {{tags}} seems to only work within a post, but not somewhere in the default template.
How can I display a full list of all tags created?

I managed to get my result using the Ghost API, however I would be surprised if this is the only way.

You should use the get helper:
{{#get "tags" limit="all"}}
<ul class="tags">
{{#foreach tags}}
<li>
{{name}}
</li>
{{/foreach}}
</ul>
{{/get}}
You can read more about get helper on docs.

Related

Is there any elegant way to show active hyperlink style?

Maybe I've missed something, but I've found that it's quite difficult to show conditional attributes in rails. Many programmers use helper methods to achieve this, but it still seems like a tedious task. I wonder if anyone has an elegant method of achieving this.
To be clear, let's say we have some css component as below (this example comes from a github opensource css framework: https://primer.style/css/components/navigation), So how would I change an 'aria-current': 'page' attribute?
<nav class="UnderlineNav UnderlineNav--right">
<div class="UnderlineNav-body">
<a class="UnderlineNav-item" href="#url" aria-current="page">Item 1</a>
<a class="UnderlineNav-item" href="#url">Item 2</a>
<a class="UnderlineNav-item" href="#url">Item 3</a>
<a class="UnderlineNav-item" href="#url">Item 4</a>
</div>
</nav>
Finally, I solve it by a helper method as the follow. If you guys have some other simple way, please let me know. Many thanks.
def active_header_link(text, slug, options)
if current_page? slug
link_to text, slug, {'aria-current': 'page'}.merge(options)
else
link_to text, slug, options
end
end
then, just call it when necessarily like this
<%= active_header_link node.name, node_path(node.slug), class: 'UnderlineNav-item' %>

<data:post.title> returns title of blog and not post title

Hi I'm trying to convert a static html and css design to a blogger template. I've run into an issue where i expect the post includable to return the post title but instead is returning the blog title. Here is the includable code for the post and below it is the include code that is called in the main includable that houses the html structure. Please any ideas as to how i might resolve this would be very grateful.
<b:includable id='post' var='post'>
<!--Article Summary-->
<b:if cond='data:post.title'>
<h1 class="article-title">
<data:post.title/>
</h1>
<b:else/>
<h1 class="article-title">
<data:post.title/>
</h1>
</b:if>
<p class="posted-by">
by
<em class="author-name"><data:post.author/></em>
on
<span class="date"><data:post.dateHeader/></span>
</p>
<p class="article-content">
<data:post.body/>
</p>
READ MORE
</b:includable>
<b:if cond="data:blog.url == data:blog.homepageUrl">
<div class="article-summary">
<img class="article-image" src="https://lh3.googleusercontent.com/article-main-image.jpg" alt="article-main-image"/>
<b:include name="post"/>
</div>
</b:if>
is correct, so instead I'd be curious about whether or not you're including from the right place. For example, are you in the MOBILE section vs the NON-MOBILE section of the template?

How do I have an Angular.dart filtered list update automatically

I have an html template that filters a list by the column property of the objects of that list like so:
<ul>
<li card-view
card-id="state.card"
ng-repeat="state in ctrl.game.states | filter:{column:'backlog'} "
ng-include="cardview.html">
</li>
</ul>
If I modify the column property in one of the elements of that list, the display does not update.
How can I make that happen?
Here's one option that uses an imaginary placeholder tag and avoids the |filter replacing it with an ng-if, but I hope someone has a better answer than this one.
<ul>
<xx ng-repeat="state in ctrl.game.states">
<li card-view
card-id="state.card"
ng-if="state.column == 'backlog'"
ng-include="cardview.html">
</li>
</xx>
</ul>
Doing the ng-if and ng-repeat on the same element didn't work.

How do I use a variable to assign a css id in an html.erb file?

I have a class in a .html.erb view file that I want to give an id based on a variable.
I want to do something like this:
<ul id="#{store}">
Where store is a variable containing the string "store1".
I want this to yield an ul like this: <ul id=store1>, but I get <ul id=#{store}> instead.
Do I need to create a helper to help facilitate this or is there some syntax I'm overlooking?
Try this:
<ul id="<%= yourvariable %>">

Rails: Rendering Multiple index.html.erb on a Single Page

I am using tabs and want to load multiple index pages into tabs. For instance:
class AnimalsController < ApplicationController
def index
#dogs = Dog.all
#cats = Cat.all
end
end
Then in my views/animals/index.html.erb
<ul class="tabs">
<li>Dogs</li>
<li>Cats</li>
</ul>
<div id="#dogs">
<%= render #dogs %>
</div>
<div id="#cats">
<%= render #cats %>
</div>
Is refactoring out into a partial the only way to achieve this?
I'd like to have them loaded statically at once and not have to resort to doing an Ajax.load() when the tab is clicked.
You have your answer in the question itself. Why don't you just use javascript to hide the two partials and call them when their respective tab is clicked? You don't need ajax for this at all :)
Since you did not mention the javascript library that you use, I will give a generic solution using jquery:
Also you need not add a # to your respective div's ids. Change it to this:
<ul class="tabs">
<li id="dogs">Dogs</li>
<li id="cats">Cats</li>
</ul>
<div id="dogs" class="subTabs">
<%= render #dogs %><hr />
</div>
<div id="cats" class="subTabs">
<%= render #cats %><hr />
</div>
$(document).ready(function() {
$('.subTabs').hide(); //Hide the subTabs as soon as the DOM is loaded.
$('li').live('click', function(e) {
$('.subTabs').hide(); //Calling this again so as to remove an already loaded
tab, if any. You can refactor this part to make it
even simpler.
$('body').find('.subTabs').attr('id',$(this).attr('id')).show();
//This finds the ".subTabs" whose id is the same as the "li" id that
was clicked and shows it. Ofcourse, even this can be made even more
compact had i known your entire DOM structure.
});
});
Edit:
You also have to make sure that you style it using CSS to make it look more like tabs if you haven't already. :)
Hope this helps. :)
You typically only want to use a partial if you are using the same or almost the same code in more than one place.
When you say "index page", do you really want to use the same code that is used in an index of another controller? If so, then a partial is the best strategy.
Don't use JavaScript to solve a layout / code organization problem.

Resources