Is it possible to display core custom fields in search results ? I can add custom fields in template override for article view like this :
<?php echo $this->item->jcfields[1]->value; ?>
It works fine for com_content but it doesn't display anything in search results (com_search).
Is there a way to render my custom fields in the search results ?
Thank you.
You can create a template overwrite for the com search component like other overwrites by creating a 'html/com_content/com_search/search' folder in your current template.
In this you copy the content of /components/com_search/views/search/tmpl
You can find a description with examples here: https://docs.joomla.org/Customising_the_Smart_Search_results_page
This is targeted at Smart Search (com_finder), however you can follow this by replacing com_finder for com_search.
Then you customize and add the custom fields in the file: default_results.php in your overwrite file.
Please note that the custom fields are a string in the $result object
["jcfields"]=>
string(26) "Custom Field,Search123,1,2"
echo "My fields: ".$result->jcfields;
If you want to do this for Smart Search in Joomla 4, here is the solution.
Create a template override of the file: components/com_finder/tmpl/search/default_result.php
At the start of the file (after line 20), add this code:
// Creates an array with all the CF of the current article.
$articleCustomFields = Joomla\Component\Fields\Administrator\Helper\FieldsHelper::getFields('com_content.article', $this->result, true);
// Creates an associative array using the custom field id as a key.
$articleCustomFields = \Joomla\Utilities\ArrayHelper::pivot($articleCustomFields, 'id');
Then print the custom fields in the page:
<ul class="fields-container">
<?php
// We are using the custom fields with ids 10 and 3
if (!empty($articleCustomFields[10]->value)) : ?>
<li class="field-entry">
<span class="field-label"><?= $articleCustomFields[10]->label ?>:</span>
<span class="field-value"><?= $articleCustomFields[10]->value; ?></span>
</li>
<?php
endif; ?>
<?php
if (!empty($articleCustomFields[3]->value)) : ?>
<li class="field-entry">
<span class="field-label"><?= $articleCustomFields[3]->label ?>:</span>
<span class="field-value"><?= $articleCustomFields[3]->value; ?></span>
</li>
<?php
endif; ?>
</ul>
If you are looking for a complete tutorial, please have a look at:
https://blue-coder.com/help/blog/adding-custom-fields-in-the-search-results
Related
I want to display two currencies in Magento's cart and invoice. I have make it in product page by this code
<div class="currency">
<?php if( Mage::app()->getStore()->getCurrentCurrencyCode() == 'USD'): ?>
<span class="price">(<?php echo round(Mage::helper('directory')->currencyConvert( $_product->getFinalPrice(), 'USD', 'AUD'), 2 ); ?>) AUD</span>
<?php else: ?>
<span class="price">(<?php echo round(Mage::helper('di`enter code here`rectory')->currencyConvert( $_product->getFinalPrice(), 'AUD', 'USD'), 2 ); ?>) USD</span>
<?php endif; ?>
</div>
and now I want to display this in the email invoice.
in the email template ti has this line
{{layout handle="sales_email_order_items" order=$order}}
looking up sales layouts we find app\design\frontend[package][theme]\layout\sales.xml
from there you can see the .phtml files used to render the items section of the email, edit the ones you need, keep in mind that these are also used on the front end.
if you want to separate the .phtml files so that the frontend and email template can use different files, copy/paste/rename sales_email_order_items in the .xml file and change the template= parts to the new templates, be sure that in your email template you change the handle stated above to what you renamed the layout to otherwise it'll use the original one.
your code should work fine, you may just need to change $_product->getFinalPrice() if it doesn't work and $_product may not be in the template or be a different class since your dealing with the the collection that deals with sales_flat_order rather than catalog_product
I am using joomala 2.5 and developed my own component for showing table data in front end and added pagination. I'm getting pagination links, after clicking on the links 'next', 'prev' nothing happens.
What may be the problem?
In view.html.php I've added
$this -> pagination = $this->get('Pagination');
In default.php I've added
<div class="pagination">
<?php echo $this->pagination->getListFooter(); ?>
</div>
You haven't mentioned what you have done in you components model file. My advoice to you is just read this document carefully http://docs.joomla.org/J1.5:Using_JPagination_in_your_component & you will be easily apply pagination. The doc is perfect & its very simple to use pagination in Joomla.
Thank you.
Put your pagination buttons inside a tag and make sure the action url points to the same view (e.g. action = 'index.php?option=com_component&view=listview')
<form action=""...>
<div class="pagination">
<?php echo $this->pagination->getListFooter(); ?>
</div>
</form>
I have a drop down magento attribute for warranty_labour. I'm pulling in the attribute using my themes product/view.phtml and then attaching an icon to show what warranty you get.
Ive used this code which successfully works:
<?php $warranty=$_product->getAttributeText('warranty_labour'); echo '<img style="padding-top: 10px;" src="/images/warrantylabour/'.str_replace(' ', '_',$warranty).'.png" alt="'.$warranty.'">'; ?>
The problem I find when a product doesn't have a warranty attribute set (left blank on the backend) I still get the code inserted on to the product source code on the frontend like this:
<img style="pad`ding-top: 10px;" src="/images/warrantylabour/.png" alt="">`
Is there a way I can stop this happening when a value isn't set in the attribute?
Don't forget logic! :-) Just test that $warranty has a value Using typical Magento template conventions:
<?php if($warranty=$_product->getAttributeText('warranty_labour')): ?>
<?php echo sprintf('<img style="padding-top: 10px;" src="/images/warrantylabour/%s.png" alt="%s"/>', str_replace(' ', '_',$warranty),$warranty) ?>
<?php endif; ?>
This kind of syntax might justify encapsulating this logic and string building into a helper method, I think.
I am trying to add a custom style to each list item within Joomla!s Category List output which gives me the following html
<div class="blog">
<div class="cat-children">
<ul>
<li class="first">
<span class="item-title">HYT
</span>
</li>
<li></li>
</ul>
</div>
</div>
I think what I need to do is add something like:
<li id="myID<?php echo $this->item->catid; ?> ">
The trouble is I can't find which file to override. I have looked in /templates/mytemplate/html/com_content/category/ as well as /components/com_content/views/category/tmpl yet none of the files seem to have a an unordered list within them that relates to cat-chidren.
So my first question is which file should I edit? And my second is what is the best syntax of this->item->[correct'Method'?] (is method the correct term or variable, I'm a little shaky on this!) to use so that each list item will have an id="myID[nameofarticle/subcatagory]"
You'll see cat-children in /components/com_content/views/category/tmpl/default.php
The ul is in another loaded subtemplate, loadTemplate('children'); ?> , i.e.
/components/com_content/views/category/tmpl/default_children.php
If you want to modify the li class you could stick something like this at line 26 (of your override not core file - but fine to just test on a core file)
<?php $class = ' class="cmyId' . $this->escape($child->title) . '"';?>
That would make each li appear as
So this
<li<?php echo $class; ?>>
<?php $class = ''; ?>
becomes this
<?php $class = ' class="cmyId' . $this->escape($child->title) . '"';?>
<li<?php echo $class; ?>>
<?php //$class = ''; ?>
Have tested it out on a 2.5 installation.
You should override several files stored in components/com_content/views/
Depending on the list you want to edit, you should then look in the folders:
- article
- category
- categories
- featured
In each of these folders you'll see a subfolder called 'tmpl', inside which there is a 'default.php' file. That's what you're looking for.
If you want to override the files remember that the best practice is to place the alternative files in your template's folder, building a similar path as the one in which the original file is (e.g. for the article folder: templates/YOURTEMPLATEFOLDER/html/com_content/article/default.php - NO tmpl folder needed, nor views folder).
An alternative and, in my opinion, easier way could be setting different templates for each category, and then assigning to each the list styles you prefer.
Or, even easier, you could simply edit your index.php file in the template's folder so that it echoes a specific css stylesheet depending on the $catId.
As your HTML code shows you are using Category Blog view, each article instance in the category is being rendered by blog_children.php file, as it shows /components/com_content/views/category/tmpl/blog.php
<?php echo $this->loadTemplate('children'); ?>
So /components/com_content/views/category/tmpl/blog_children.php is the file you need to edit or override in template html directory.
Then you can apply custom styling adding an id or class for each article with $child->id.
I need to theme views in Drupal 7. There is a content type 'Book' and I need to list 5 books and theme them in special manner(preview image, title and author).
When I override views-view-field.tpl.php and print raw SQL result, I see that all fields are displayed. This code
echo "<pre>";
print_r($row);
echo "</pre>";
gives
[entity] => stdClass Object
(
[title] => ...
....
[nid] => 34
...
[body] => Array
...
But I don't want pass [body] from database to php side, because it can be huge and cause a performance issue. I haven't selected [body] in view settings.
Is there a way to pass only certain fields to views-view-field.tpl.php?
Thanks in advance.
The variables available are written in the documentation inside the sites/all/modules/views/theme folder's files.
Usually, the variable you need to look at and modify on a views-view-fields.tpl.php template is $fields
I use the devel module (http://drupal.org/project/devel) to view the variables available:
<?php
//after enabling the devel module...
dpm($fields);
// This will print a Kuomo display on the page with the array's vars
?>
Generally, on a view of nodes,
<?php print $fields['title']->content; ?>
will print the node title. For fields, try
<?php print $fields['field_FIELDNAME']->content; ?>
If you have the memory, you can capture ALL vars available on the template in the Kuomo with
<?php dpm(get_defined_vars()); ?>
Make sure you clear your cache before you try to view the vars.
If what you want to do is theme a certain field you can create a template for that specific field like this one: views-view-field--field-nameofmyfield.tpl.php place it in your theme folder and rescan the templates in the Theme:information part of the View configuration.
For that to work you have to have the field added to Fields in the View.
To sort through your information in a theme use this:
<?php dpm ($rows); ?> // View all the information in the view
<?php foreach ($rows as $row_count => $row): ?>
<?php print $row['title'];
<?php print $row['nid'];
<?php endforeach; ?>
If you want to change of theme of view then Change views-view-fields.tpl.php like this:
<div class="pagecontent">
<div class="colleft">
<?php if($fields['field_file']->content){ ?><div class="views-field-file"><?php print $fields['field_file']->content; ?></div><?php } ?>
</div>
<div class="colright">
<div class="views-field-title"><?php print $fields['title']->content; ?></div>
<div class="views-field-body"><?php print $fields['body']->content; ?></div>
<div class="views-field-view-node"><?php print $fields['view_node']->content; ?></div>
</div>
</div>