I want to create a module for add a dynamic grid on cms page like this:
I'm able to create custom field like text or file but I don't know how can I add (remove) multiple elements, I don't find any example/tutorial, can you give me some tips or some link?
edit:
studying magento code into Varien/data/form/gallery I find a way, I use gallery.php element as starting point and then I create my element, the problem is how to save the data, for now I save the data into a column as an array or json
$aa = "[";
foreach ($_FILES as $file)
{
$aa = $aa . $file["name"]["-1"] . ",";
}
$aa = $aa . "]";
$aa = str_replace(",]","]",$aa);
$model->setBackground($aa);
I,m able to get this value but I don't think is the best way, is better create a custom magento model?
Related
I have a Drupal commerce website with about 100 000 products. Now customer wants me to change product image filenames and add alternative(alt) texts to images for all existing products - based product names and colors.
File field paths seemed to be great to changing the file names of image files. But I just cannot figure out how to add alt texts to images automatically. I've been trying hook_file_update, hook_file_presave, hook_entity_presave etc. I'm trying to add alt text during File field paths' batch update and all of the hooks are running but for some reason alt text data is not saved to entity.
Product image field is type of Image with Media browser widget.
Any help for this?
Here's hook_entity_presave() code:
if ($entity->type == 'image' && (empty($entity->alt) || empty($entity->field_file_image_alt_text))) {
$product = _get_referenced_product($entity->fid);
if ($product) {
$full_product = commerce_product_load($product->product_id);
$title = $full_product->title;
if (!empty($full_product->field_search_color)) {
$search_color = $full_product->field_search_color[LANGUAGE_NONE][0]['tid'];
$search_color = taxonomy_term_load($search_color);
$color_name = $search_color->name;
}
$entity->alt = $title . ' ' .ucfirst($color_name);
$entity->field_file_image_alt_text = $title . ' ' .ucfirst($color_name);
object_log('Entity', $entity);
object_log('Type', $type);
}
}
I had the same issue and I updated the alt tag of all images in my articles. Note, in my case I wanted to updated nodes.
And, I used following code:
https://www.gyanblog.com/gyan/34-how-add-alt-attribute-images-all-my-drupal-articles-or-other-content-type/
Actually the problem in my case was that I was trying to set alt field value in wrong way. "Field_file_image_alt_text" field the image element is using is a normal textfield so it clearly needs the following data structure.
$file->field_file_image_alt_text[LANGUAGE_NONE][0]['value'] = $title . ' ' .ucfirst($color_name);
$file->field_file_image_alt_text[LANGUAGE_NONE][0]['safe_value'] = $title . ' ' .ucfirst($color_name);
So just a stupid mistake by me! And btw, I ended up using hook_file_presave() hook.
I am working on a project that it's a bit over my basic level of web development I am not able to understand how to get specific data from my SQL and show it follow by a button that will show the entire data of the specific row a small example how it has to look on my html its:
Name. Postcode telephone (button view more ).And the next row will be the same. Hope this it understandable I can't wait for an answer.
For the first part of your question here is how you take data from database with php and show it on the page. Read this Also there are a several way to do that, more example you can find here if you interested...
For second part of your question to show data on specific location on your page, you should't just echo data instead of that place your code in variable something like this:
if ($result->num_rows > 0) {
$myTable = "<table><tr><th>ID</th><th>Name</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
$myTable .= "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]. "</td></tr>";
}
$myTable .= "</table>";
} else {
echo "0 results";
}
end then in your page i figured out it's organized as larger table just place variable $myTable where you want to be. Something like
<td class="">$myTable</td>
GL!
P.S. note that when you continue string for my table you have .= (dot equal) sign if you miss it it won't work as you expect..
How can I show the full text of a leading article (even if it contains a read more) on a Category Blog Layout?
Is there a back-end setting I can change or which PHP file do I need to overwrite? I only want the leading article's fulltext to show, intro articles should still display the readmore with only intro text.
Thanks in advance.
You don't specify which version of Joomla! so this reply is based on 2.5.x
You will need to create a layout override for com_content, specifically for the category view tmpl file blog.php or blog_item.php.
If your template already has an override installed for com_content you will find it at this location:
/templates/your-template/html/com_content/category/
If not you can copy the original files from your Joomla! 2.5's component directory at /components/com_content/views/category/tmpl/
In that directory you will find a series of files starting with blog and ending with .php - you can override 1 or all of these by coping them to the first path listed above. N.B. Only copy the files you need to change Joomla! is smart enough to look in the default directory if it doesn't find a version in the overrides location.
The default Joomla! 2.5 installation has these blog files:
blog_children.php
blog_item.php
blog_links.php
blog.php
Basically blog.php is the main file and it includes the sub-layouts like blog_item.php as required.
If you're working from the default Joomla! 2.5 files, to achieve your goal you will probably have to override blog.php and blog_item.php and find a way to check whether you are in the leading item. Once you know that your in a leading item you will then want to echo out the full text of the item.
blog_item.php normally just outputs the intro text with a line like this:
<?php echo $this->item->introtext; ?>
You'll want to have the full text echo'd so after you've wrapped the line above in an if to check if you're doing the leading item your output line will look something like this:
<?php echo $this->item->introtext.$this->item->fulltext; ?>
Note: I've haven't check this works it's just speculation and relies on the $item having the full row from the #__content table.
So the articles full text isn't added to the article item in a standard install i.e. you can simply echo $this->item->fulltext.
There are two ways to get the full text.
The simplest & first is to modify the core file at /components/com_content/models/articles.php starting with the first $query->select() in the function getListQuery() which starts on/near line 153. Add ' a.fulltext,' after the a.introtext and before the single apostrophe, so the line looks like this:
function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, ' .
'a.checked_out, a.checked_out_time, ' .
The second way, and the Joomla! update proof way (& therefore probably the better way) is to load the entire article in the override (ugly but it's not a hack) and concatenate the fulltext to the introtext of the first article.
To do this you simply use getTable to load the article using the $this->item->id in blog.php for the first leading item, so at about line 54, between the <?php and the $this->item = &$item; put:
if($leadingcount == 0) {
$contentTable = JTable::getInstance('Content');
if($contentTable->load($item->id)) {
$item->introtext .= $contentTable->fulltext;
}
}
N.B. The if just limits it to the first leading article, if you remove the if it will attach the full text for all leading articles.
This works on my dev installation of Joomla! 2.5.6 so you should be able to do it as well.
Considering the two answers above, there are three changes required to blog.php and blog_item.php. This works in Joomla 3.1 The best is to copy these files to the template override
copy blog.php and blog_item.php
from components/com_content/views/category/tmpl/
to [my template]/html/com_content/category/
In blog.php in the loop for the leading items add one single line:
<?php foreach ($this->lead_items as &$item) : ?>
<div class="leading-<?php echo ...?>">
<?php
$this->item = &$item;
$this->item->leadingItem = true; //ADD THIS LINE !!!
echo $this->loadTemplate('item');
?>
</div>
<div class="clearfix"></div>
<?php
$leadingcount++;
?>
<?php endforeach; ?>
In the blog_item.php replace "echo $this->item->introtext;" with
if ($this->item->leadingItem){
//this is a leading article - show full text and remove "Read more..." button
$itemID = $this->item->id;
$db =& JFactory::getDBO();
$query = "SELECT `fulltext` FROM `#__content` WHERE `id` =" . $itemID;
$db->setQuery($query);
$fulltext = $db->loadResult();
echo $this->item->introtext . $fulltext;
}else{
echo $this->item->introtext;
}
Finally in the blog_item.php do not to show the "Read more..." button at the bottom of each article
Edit line
if ($params->get('show_readmore') && $this->item->readmore)
into
if ($params->get('show_readmore') && $this->item->readmore &&
!$this->item->leadingItem)
Joomla 2.5.x, in your template blog_item.php:
$itemID = $this->item->id;
$db =& JFactory::getDBO();
$query = "
SELECT `fulltext`
FROM `#__content`
WHERE `id` = $itemID;
";
$db->setQuery($query);
$fulltext = $db->loadResult();
and you can use the $fulltext string variable.
I want to create a page in the Magento CMS, then echo specific category descriptions on it. What is the code snippet i will need to accomplish this. I am assuming I will need to reference the categories' unique id within the database to echo their description...
thanks for the help!
john
Using PHP:
$categoryId = 15;
$category = Mage::getModel('catalog/category')->load($categoryId);
if($category->getId()) {
echo $category->getDescription(); // Should escape this, blocks have $this->escapeHtml()
}
I don't know how to do this using magentos email/cms template markup (I don't think its possible) - unless you create a block or widget.
How can I read the section a certain URI belongs to?
I want to enhance the mod_breadcrumb to put section and category into the HTML. JApplication->getPathway() returns a JPathway which basically holds an assiciative array combining a name and an URL (as $list[]->name and $list[]->link). I think, it should be possible to get the section and category from a link, but don't know how.
A starting point could be the parsing into JURI-Object, but from there I don't know how get get further. Any ideas?
Pretty straight forward...
I assume you want to add category and section for the article and not your custom component.
Check if requested current URL is for article. If it is for article you know the article ID, use this article Id to go database and get catid from #__content, Use this cat_id to go to #__categories and get section (this is section id), go to #__sections to get the proper section name. All this can be done in 1 sql statement.
$breadcrumbs =& JFactory::getApplication()->getPathway();
$breadcrumbs->addItem("SECTION_NAME", JRoute::_("index.php?option=com_content&view=section&id=SECTION_ID"));
$breadcrumbs->addItem("CATEGOY_NAME", JRoute::_("index.php?option=com_content&view=category&id=CATEGORY_ID"));
$breadcrumbs->addItem("Article");
Alternatively, if you know the URL from the breadcrumb item. You can parse it and get IDS. The trick here is not to get the default URI object by JFactory::getURI() because things will get ugly, use JFactory::getURI('YOU_URI_NAME').
<?php
// You need to get Your own uri, you do not want to modify default URI
// because this will messup a lot of things
$uri = JFactory::getURI('MyCustomURI');
// Test # 1 [ID = SECTION_ID]
$url = "index.php?option=com_content&view=section&id=SECTION_ID";
$uri->parse($url);
echo "CURRENT SECTION = " . (int) $uri->getVar('id');
// Test # 2 [ID = 123]
$url = "index.php?option=com_content&view=section&id=123";
$uri->parse($url);
echo "CURRENT SECTION = " . (int) $uri->getVar('id');
?>