Page 1 of 1

Media Tags and the images for Categories

Posted: Mon Oct 29, 2012 9:43 am
by limebot
I found an update at this URL ( http://jira.broadleafcommerce.org/browse/BLC-577 ) which added Media tags. Can you explain the use for this update last August.
One of the main reasons is I am searching for a way to display images for a category. (Example: show a page of manufacturers logo`s) So when clicked It takes to you the page of all of their products.

Any way to do this is the current Demo Project?

Re: Media Tags and the images for Categories

Posted: Tue Oct 30, 2012 9:20 am
by limebot
I have this code which prints out the Child category names, I can also print the Descriptions but I am looking for the Media code to pull in the category image that I saved in the admin.

<ul th:if="${#objects.nullSafe(category,default)}" class="sub-menu">
<li th:each="cat : ${category.getChildCategories()}">
<a th:text="${cat.name}" th:href="@{${cat.url}}" />
</li>
</ul>

Do you have examples that will pull in the images tagged to the Categories?

I guess something like this?

<img th:="*{media['primary']}" th:src="@{*{media['primary'].url}}" alt="" />

Re: Media Tags and the images for Categories

Posted: Tue Oct 30, 2012 12:40 pm
by phillipuniverse
If you look at the Category interface, there is a method called 'getCategoryMedia' which gives you a hashmap of String -> Media. This is what you are managing in the admin when you add/remove/edit media for a category.

So, that means if you want to use this map on the frontend you would do pretty close to what you have there:

Code: Select all

<img th:src="@{*{categoryMedia['primary'].url}}" />


The tags that you were referring to are really just for product options. Say that you're selling shirts and you offer a blue shirt and a red shirt. Then say you have different pictures for a red and blue shirt. You can tag those 2 media items with 'blue' and 'red' and then have javascript to select the best media for the selected product option.