I've created some custom field in my taxonomy vocabulary called Categories:
- fotogallery (multiple files)
- incipit (plain text)
- ...
But I don't know how to render them.
I've tried field_view_field but it refers just to entity. I've tried render and drupal_render also.
Actually I'm accessing directly to $term->field_incipt['und'][0]['safe_value'] property, that I konw it's not recommended.
Any ideas?
Taxonomy terms in Drupal 7 are entities, and as such you can use field_view_field()to safely get the render array:
$view = field_view_field('taxonomy_term', $term, 'field_incipt');
print render($view);
the field_view_field function works for me.
just note you need to send the term entity.
you can get one using entity_load
i.e. $term_entity = entity_load('taxonomy_term', array($tid));
To properly get $term object, you should use taxonomy_term_load() function and pass term id to it.
Related
I am using the "taxonomy display" module. I use to so that I can sort my taxonomy terms by title, instead of by ID, as it does by default. However, I also created a taxonomy template called:
taxonomy-term--product_literature_category.tpl.php
If I enable the "taxonomy display" module and override the taxonomy view for this path:
/taxonomy/term/%
... it also overrides the template I specified above. It would make more sense that the order would be to take my custom template override the module. But it doesn't seem to work that way. But if I disable "taxonomy display", it again takes my template into account.
I have two choices:
Enable "taxonomy display" and find a way to override taxonomy-term--product_literature_category.tpl.php
Disable "taxonomy display" and find a way to sort taxonomy terms by my own custom sorting parameters.
I would imagine 1 being difficult (because it doesn't make much sense to use two templates for the same thing). That is why I'm leaning towards an easier way to sort taxonomy views by default, or some other way to specify the ordering of taxonomy terms.
Does anyone know how to do this?
UPDATE
Right now I am going to settle with figuring out a hook to change the sorting of taxonomy terms via a module. That way I can override the sorting for only specific vocabularies. Any pointers to nudge me in that direction would be highly appreciated?
UPDATE 2
I've created teaser_sorter.module and added this function:
function teaser_sorter_views_query_alter(&$view, &$query)
{
print '<pre>'; print_r($view); print_r($query); die();
}
I also made sure my module supports views:
function teaser_sorter_views_api() {
return array(
'api' => 3,
);
}
I can't get it to ever reach my "die". In other words, it's never called. In fact, I also tried overriding "hook_views_pre_execute", but that doesn't ever get called either.
Any ideas?
view : <google-taxonomy-category class="googlecategoryselectiontool" field-name="goo_cat_id" cat-sel=""></google-taxonomy-category>
"class" used for template setup so if I want to use any.tpl then I simply have to write tplname. if no class value given then it will take default template.
"field-name" it will consist name of the request variable which you want to set on checkbox. by default its value going to be "selected_value[]" if no value passed for it.
"cat-sel" it will consist of data of which category need to be selected when html load. it will take value like <?php echo htmlspecialchars(json_encode($selected_value)); ?> in
which $selected_value is the array of all category id which need to be selected.
I use taxonomy terms to address my menus(these taxonomy terms show the structure of my site) so when I create a view I should use the taxonomy path (instead of alias) for the page setting (the only way that I can link the view to my taxonomy address path as far as I know :P ). whenever I see the page URL I can see the alias. now I'm trying to set up a page that has 2 tabs. I have set it up but the problem is when I click in the tab I see the taxonomy path instead of alias ? (for example taxonomy/term/6/digital instead of CCTV/digital However default menu tab still work correctly and show the alias CCTV)
Is there any way to show the alias instead of taxonomy term address ?
I assume that you have a view that is filtering your taxonomy terms. If you render the results as fields, each field can have it's formatter. If you need a custom form of the output, you can define your own formatter or generate one via GUI with help of: custom formatters.
In case that you render your output as rendered entity, you need to find the right template file and use the drupal_get_path_alias() function within it.
As last I would hint you a great module that also might help you: taxonomy menu
i need to create a component dynamically by a button click. My restrictions are:
It's going to has an Id starts with a fixed string like 'myComp_' and followed by a random number
At any time there will be only one component that has an id starts with 'myComp_xxx'
So before creating the component i have to check if there's any created before and remove it... My problem starts here. Ext.getCmp() wants the specific id. But i only have that fixed string : myComp_...
Is there any way to get the component created before???
Thanks in advance and sorry about my English.
For ExtJs 4.X use Ext.ComponentQuery.query('*[id^=myComp_xxx]');
For ExtJs 3.X you can either use the following
var el = Ext.query('*[id^=myComp_xxx]');
var cmp = Ext.getCmp(el.id);
Or (this one i haven't tried personally, but i think it should work) if the component is a child of a component that you can access, then:
var el = parentComp.find("action","btn");
and set a property called action : btn in the button config.
I think what you are looking for is DomQuery.
Ex:
Ext.query("*[id^=myComp_xxx]")
You need to use this: Ext.getCmp(id)
Ext.getCmp("myComp_xxx");
Sounds like you should be using the normal component query stuff - in general it is not a good idea to use id. You can query by xtype and by itemId (which you can assign manually).
The following
Ext.ComponentQuery.query('grid form');
would find all things with xtype grid that have forms inside them somewhere.
Ext.ComponentQuery.query('grid #okButton');
whereas the # here is saying look for grids that have something with itemId 'okButton' in them.
You can nest this to whatever level you need and use other operators to be more specific and as someone else has rightly pointed out you can use up and down on components to do this relative to the current component. Its worth noting that rather than getting an array back with all the results you just get the first one when you use up and down.
See the documentation for more information this.
Also see point 6 on this list of bad practices to avoid for more of the why
Another alternative if you know 'where' your component is going to be created is to use the up()/down() methods.
E.g. if you have a button and want to get the form it's contained within inside a click handler you can do something like this:
function myClickHandler(btn) {
var form = btn.up('form');
//do something with form
}
I have a Drupal 7.9 taxonomy vocabulary according to the following scheme:
category-1
category-1 > subcategory-1-1
category-1 > subcategory-1-2
category-1 > subcategory-1-3
category-2
category-2 > subcategory-2-1
I want to reflect this taxonomy hierarchy in my page url path like
category-1/subcategory-1-1/page-123
To achieve this I'm using the modul Pathauto version 7.x-1.0. but I don't know
which pattern I have to use.
Currently I'm using [node:%field_taxonomy%]/[node:title] but with this pattern the url path is just subcategory-1-1/page-123, so the complete hierarchy isn't reflected. Is there a taxonomy tree pattern? I can't find any updated information about this and valid patterns seem to change in every version of Pathauto.
After some trial and error I came up with a way which works pretty good for me while creating custom URL paths using taxonomy terms. All you need to do is to install an additional module called Entity API. You can find it here http://drupal.org/project/entity. After installing you should enable both Entity API and Entity tokens modules. Entity tokens provides token replacements for all properties that have no tokens and are known to the entity API.
First, go and create a new taxonomy vocabulary. Let's call it "Category" and add some terms. Then for a content type you want to have a custom URL path you need to create a new term reference field. I don't know why but it's not working with the standart field_tags. So, make sure to create a new one. Let's also call it category and use our previously created vocabulary "Category" as the source. And here's another thing you need to take into account: you have to label this field with a small letter; otherwise it's not working for an unknown to me reason ;). You'll end up with a field_category field.
Go to URL Aliases administration page -> Patterns. Expand replacement patterns for Content paths -> expand Nodes -> you'll see category at the bottom, expand it. Ok, now you're ready to use taxonomy terms tokens.
Use something like [node:field-category:name]/[node:title] where [node:field-category:name] is the name of the taxonomy term and you'll have a path like mysite.com/term/title.
By the way, I use Pathauto 7.x-1.0-beta1, Token 7.x-1.0-beta2 and Entity API 7.x-1.0-beta8.
Good Luck! ))
http://drupal.org/node/1044980#comment-4562844
You can create url with this pattern:
[node:field-category:vocabulary:name]/[node:field-category:parents:join:/]/[node:field-category:name]/[node:title]
In your particular situation you can go away with using following pattern for taxonomy items:
[term:vocabulary:name]/[term:parent:parent]/[term:parent]/[term:name]
And for node pattern:
[node:%field_taxonomy%:url:path]/[node:title]
There is downside tho - term pattern will handle up to three levels in this case. So you can not make it unlimited with this approach. (I believe you can add term:parent:parent:... as many as you want).
Although, it will handle LESS than 3 levels fine (just tested to make sure).
As far as I know, basic Drupal + Token + PathAuto is not able to create paths, like you want them to.
Check my answer here. You can use the taxonomy entity index module for achieving such behaviour.
Developing my custom Drupal's theme. it will contain custom node.tpl.php file.
How can i get and print related taxonomy names of selected node?
Tnx in adv!
EDIT: Doh, my apologies, I'm just now seeing the Drupal 7 tag, specifically. It appears this thread has some possible solutions: http://drupal.org/node/909968
With D6 (not 100% about D7) In the node's template .php files (and similarly, in a view or most anywhere you have access to a node's properties with custom PHP, like a View or Block), you can use the following:
// returns array of taxonomy objects for given node
$tax_terms = taxonomy_node_get_terms($node);
// prints each term name
foreach ($tax_terms as $tax) {
print $tax->name;
}
Also, there's a few useful Drupal functions for cases like this:
// print_r's all properties of a given node, similar to devel
dpr($node);
// using this in the above 'for' look will give you all properties of each taxonomy object
dpr($tax);
Here's a website that lists a few more of these functions.