I understand it's better to write browser view in a product, but want to know if there's any quick solution to the following task.
I have a custom Dexterity type with a cities field:
cities = schema.List(
title=_(u"Cities"),
value_type=schema.Choice(
vocabulary='cities',
required=False,
),
)
Values in the vocabularies.py look like:
SimpleTerm(value="NewYorkCity", title=_(u"New York City")),
Now I want utilize Skin-based template folder_listing.pt and add the following to display the cities values.
<tal:cities condition="item_obj/cities"
tal:repeat="city item_obj/cities">
<span tal:replace="city">Value</span>
<span class="separator" tal:condition="not:repeat/city/end">,</span>
</tal:cities>
It displays the results as NewYorkCity, but I really want is its translated title in Chinese, like 紐約市. If feasible, how can I meet this needs with template customization?
I think that you just need to use i18n:domain and i18n:translate :
<span i18n:domain="yourdomain" i18n:translate="" tal:replace="city">Value</span>
(see http://wiki.zope.org/zope3/ZPTInternationalizationSupport)
Related
So I have an easy-search template as such:
{{> EasySearch.Autosuggest index=PlayersIndex labelField="Player" valueField="Team"}}
My index is defined as:
export const PlayersIndex = new Index({
collection: Stocks,
fields: ['Player', 'Team'],
engine: new MinimongoEngine(),
});
And I want the autosuggest box to display both the Player and the Team. Right now it just shows the Player. How can I achieve this?
You should first visit the autosuggest's documentation which is pretty short. From there it's pretty clear that only the first member of the fields array (in your case "Player") is chosen as the value to present when searching. To change this behavior you can pass a different template through the renderSuggestion parameter that EasySearch.Autosuggest seems to accept. By default it's using the
EasySearch_Autosuggest_DefaultRenderSuggestion template which you can find here. You can just create your own template in one of your files
<template name="playerTeamAuto">
<div>
<span class="autosuggest-title">
<span class="name">{{label}}</span>
<span class="teamName">{{doc.Team}}</span>
</span>
</div>
</template>
This will work only for your set of results where the returned documents would have a guranteed field of Team that's why we can access it through the doc variable. This comes from the object that the template is rendered with here on this specific line. As you can see it has all the data fields returned through the form of item, as even the label is gotten from there. I've added a between the player and team name, but you can format them any way you want.
I'm working on a website with a feature that can sort users.
I'm using mvcgrid.net libs but I can't figure it out. the toolbar doesn't work.
I used most of the basic source codes from mvcgrid.net but when i press something in the search bar it doesn't work or the items per page selection.
If you have specific code to take a look at, please post. Otherwise, here are a few things you can check:
(1) Be sure you've applied the mvcgrid data attributes needed. For example, for a search field you might have these attributes:
<input
type="search"
data-mvcgrid-apply-additional="change"
data-mvcgrid-type="additionalQueryOption"
data-mvcgrid-option="search"
data-mvcgrid-name="ContactGrid">
(2) Be sure the value you chose for mvcgrid-option (in this example, "search") is then added when you configure the grid. For example:
MVCGridDefinitionTable.Add("ContactGrid", new MVCGridBuilder<ContactViewModel>(defaults)
.WithAdditionalQueryOptionNames("Search")
...
(3) You then need to read the attribute (again in the grid config) in your .WithRetrieveDataMethod()
string search = options.GetAdditionalQueryOptionString("search");
I've forgotten step 2 in the past -- that's generally what has tripped me up.
I'd like to translate each node title as a string (using i18n). I'm trying this function in my theme template:
function theme_process_page(&$variables) {
$variables['title'] = t($variables['title']);
}
Yet when I refresh strings, none of my node titles are on the list. Is there something I'm missing?
And to clarify the function name is using my theme name, not the word "theme".
Title is my usual solution for this (I use Entity Translation, it works fine with Title module).
This module replaces node titles by a regular translatable text field. You can choose wich content type titles must be replaced (on the "Manage Field" forms, you'll find a "replace" link in the title row). Pretty useful.
Good luck
You should never use t() to translate user-supplied or variable strings. See the documentation on the function.
That said, there are some solutions, one is to use the built-in language support for entity fields. Following that you should be able to do something like this in a field hook (in a module, not in your template):
$langcode = $field_info['translatable'] ? $content_langcode : LANGUAGE_NONE;
$entity->{$field_name}[$langcode][0]['value'] = t("Salut!");
I am rather new to Symfony (2 weeks) so forgive my ignorance.
I am trying to add a custom action button that will link to a pre filtered list of a RELATED entity. I have done a lot of research but can't quite seem to find what I need.
Currently I have two entities Books and Authors with a manyToOne relation ship.
I have these set up in Sonata Admin in the usual way and all works well. I even have an author filter on the book list page which I am hoping can be leveraged to accomplish my goal.
In the Author list view, I would like to add an action button on each row next to View and Edit, called "View Books By Author". I can get the button but fail to correctly build the URL.
I have 3 issues with the routing:
1) I am trying to use admin.generateObjectUrl() or similar in my button template to cleanly build an admin URL but can't get a path to an alternate entity. In my case, since I am currently viewing authors, the links always point to the author entity not books as I would like.
2) I am uncertain how to get the id of the current author in order to pass it to the filters
3) I am uncertain how to cleanly build the filter query string parameters. I could do it by hand if necessary: bookEntityListPath + "?filter[author][value][]=" + $authorID
But obviously this is not that clean and I would prefer a better method if possible.
Thanks in advance!!!
I had the same issue and started trying out some code when I could not find an answer. Using the path() twig method (route to path conversion) it is quite easy to create a link like that.
See this documentation: http://symfony.com/doc/current/book/routing.html#generating-urls-from-a-template
Your link would look something like this:
<a href="{{ path('admin_application_book_list', {
'filter[author][value]': object.id
}) }}" class="btn btn-small">
With 'admin_application_book_list' being the path to the list of books (bookEntityListPath?) and object.id being the id of your author (would have the name object in a detail or edit template of that entity)
I'm using Plone v4.1.2, and I'd like to know if there a way to include more than one author in the by line of a page? I have two authors listed in ownership, but only one author is listed in the byline.
I'd like the byline to look something like this:
by First Author and Second Author — last modified Jan 11, 2012 01:53 PM — History
UPDATE - Thanks everyone for your replies. I managed to bungle my way through this (I've never used tal before). I edited plone.belowcontenttitle.documentbyline as suggested by Giaccamo, and managed to learn a bit about tal along the way. Here is the code that does what I needed (this replaces the existing tal:creator construct):
<span>
by
<span class="documentCreators"
tal:condition="context/Creators"
tal:repeat="creator context/Creators"
i18n:translate="text_creators">
<span tal:define="cond1 repeat/creator/start; cond2 repeat/creator/end"
tal:condition="python: not cond1 and not cond2" >, </span>
<span tal:define="cond1 repeat/creator/start; cond2 repeat/creator/end"
tal:condition="python: not cond1 and cond2" > and </span>
<tal:i18n i18n:translate="label_by_author">
<a href="#"
tal:attributes="href string:${context/##plone_portal_state/navigation_root_url}/author/${creator}"
tal:content="creator"
tal:omit-tag="python:view.author() is None"
i18n:name="author">Roland Barthes</a>
</tal:i18n>
</span>
</span>
This puts the userid on the byline instead of the full name. I tried to get the full name, but after some time without success I decided I could live with userid.
In order to browse more than one author you'll need a little bit of coding:
That piece of page is called viewlets.
That specific viewlet is called plone.belowcontenttitle.documentbyline.
You can use z3c.jbot to override the viewlet template. Take a look at this howto for usage. Another option is to customize the template through-the-web following this tutorial.
you could use the contributors- instead of the owners-field. they are listed by default in the docByLine. hth, i