In Apache Sling, I can do something like this with HTL/sightly:
<div data-sly-list="${resource.listChildren}">
<p>title: ${item.title}</p>
</div>
Variable resource points to the current path of, say, /a/b/c. How can I get a resource at /x/y/z and list its children? That's through the resolver global variable but I am unclear about the syntax to be used.
You can use data-sly-use to grab a Resource object for a given path:
<sly data-sly-use.test="/content/core-components-examples"></sly>
<ul data-sly-list="${test.listChildren}">
<li>${item.path}</li>
</ul>
Related
I am working on a project with 2 app (builded with python/flask).
The first one app. py is the server
The second client.py is the client side.
Now I am building link to acces users/8 from users
But it does'nt work
here under users.html / client.py #route /eror message from jinja
users.html:
{%block body%}
<div class="users">
<div class="list-group">
{% for user in users %}
<a href ="{{ url_for('users/%s'%user[0]) }}" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{user[1]}}</h5>
<small>{{user[0]}}</small>
</div>
<p class="mb-1">{{user[2]}}</p>
<small>Know more...</small>
</a>
{% endfor %}
</div>
</div>
{%endblock%}
client.py:
#client.route('/users/<id>')#ok works
def user(id=None):
if 'logged_in' in session:
r = actualUser.get(id)
user=json.loads(r.text)
return render_template('user.html', user=user)
else:
return redirect(url_for('login'))
error message:
File "/home/elodieb/Rendu/Python/Flask/flask_d02/ex_03/Client/templates/users.html", line 1, in top-level template code
{%extends "base.html" %}
File "/home/elodieb/Rendu/Python/Flask/flask_d02/ex_03/Client/templates/base.html", line 44, in top-level template code
{%block body%}
File "/home/elodieb/Rendu/Python/Flask/flask_d02/ex_03/Client/templates/users.html", line 12, in block "body"
<a href ="{{ url_for('users/%s'%user[0]) }}" class="list-group-item list-group-item-action">
werkzeug.routing.BuildError: Could not build url for endpoint 'users/7'. Did you mean 'users' instead?
Looks like the users.html is looking for an users list (see {% for user in users %}) and you are passing a single user instance (render_template('user.html', user=user)).
Either you can modify the template and not use the for in loop or update the call to render_template like so render_template('user.html', users=[user])
The error message is pretty explicit here. The issue is an invalid use of the url_for function within the users.html template. You have written this
url_for('users/%s'%user[0])
But url_for expects an “endpoint” argument (i.e. the name of the corresponding route, here it is 'users') and variables to be passed as keyword arguments. More information and examples on usage here: https://flask.palletsprojects.com/en/1.1.x/quickstart/#url-building
Therefore, what you should replace that template instruction with is
url_for('users', id=user[0])
You'll probably end-up having other errors after having fixed this though, because you are passing a single user=user variable to your template whereas you want to loop over a users collection.
I'm trying to iterate over a list and pass the current iteration and another model variable to a fragment, but the "other" model variable is always null.
<div th:each="place : ${results.placeResults}" class="col-sm-6 col-xl-4 mb-5">
<div th:replace="fragments/placecard :: placecard" th:with="place=${place},res=${results}"/>
</div> <!-- end for each-->
In the fragment ${res} is always blank.
I figured it out, the th:replace basically makes the th:with have no effect. I changed the code to use th:include and things look better.
There is the structure like:
<div class="parent">
<div>
<div class="fieldRow">...</div>
</div>
<div>
<div class="fieldRow">
<div class="CheckBox">
</div>
</div>
<div>
<div class="fieldRow">...</div>
</div>
<div>
<div class="fieldRow">...</div>
</div>
</div>
In my script I am writing a loop for each of the 4 div's under div[#class='parent'] and aiming to click the checkbox if there is, i.e.
members = page.all(:xpath, '//div[#class='parent'])
members.each do |a|
if **page.has_xpath?(a).find(:xpath, "div[#class='fieldRow']/div[#class='CheckBox']")**
a.find(:xpath, "div[#class='fieldRow']/div[#class='CheckBox']").click
end
end
However I can't look for the correct usage of has_xpath? with xpath including variable.
Please advice? Thank you!
has_xpath? takes an XPath expression (not an element) and returns a boolean (true/false) based on whether there are any elements that match that expression within the current scope - http://www.rubydoc.info/gems/capybara/Capybara/Node/Matchers#has_xpath%3F-instance_method. Since it returns true/false you can't then call find on it. For the example you posted there's no need for XPath or checking for the existence of the elements, just find all the matching elements and call click on them. Something like
page.all('div.parent div.fieldRow div.Checkbox').each { |cb| cb.click }
or
page.all('div.parent div.Checkbox').each { |cb| cb.click }
if the fieldRow class isn't something you really need to check.
Note: this assumes clicking the elements doesn't invalidate any of the other matched elements/change the page.
If you REALLY need to do it with the whole members and looping on them , using XPath, and checking for presence then it would be something like
members = page.all(:xpath, './/div[#class='parent'])
members.each do |a|
if a.has_xpath?(:xpath, ".//div[#class='fieldRow']/div[#class='CheckBox']")
a.find(:xpath, ".//div[#class='fieldRow']/div[#class='CheckBox']").click
end
end
Note: the .// at the beginning of the XPath expressions is needed for scoping to work correctly - see https://github.com/teamcapybara/capybara#beware-the-xpath--trap - which is an issue using CSS selectors doesn't have, so you should really prefer CSS selectors whenever possible.
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.
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 %>">