Hello,
I’m wondering how can I link Banners to Category page insted of ProductPage?
Regards,
Iyad
Hello,
I’m wondering how can I link Banners to Category page insted of ProductPage?
Regards,
Iyad
Do you have a banner block or similar that you want to link to a category?
Are you asking for the UI or for the code?
Which version of Litium?
Yes, i have copied the banner block.
Code for starters.
Litium Version 7.2
Add the “Link To Category” pointer field to the Banners fields (Multifield section) first.
Then add your logic in method “Resolve” in BannersBlockViewModel.cs on which link to pick.
You can get the link like this:
var linkToCategory = block.GetValue<PointerItem>(BlockFieldNameConstants.LinkToCategory)?.MapTo<Category>().MapTo<LinkModel>();
Thanks, I will try it
So I tried to place that line in the code as you said, but I still gett Null.
I tried to CategoryLink - Blouses And the other one to Woman.
Still both comes back as null.
Did you add the LinkToCategory field to Banners field in the fields section?
Yes. I have a field Called CategoryBanners and it has the following fields:
*Category Banner Text (Working).
*LinkToCategory (not working)
*Image (working).
Now im getting Mapping exception…
Yes ok first answer were not tested by us and was set in theory but this should work since I tested it.
Add this lines in The Resolve method in BannerBlockItemViewModel.cs instead.
var linkToCategory = source.Fields.GetValue<PointerItem>(BlockFieldNameConstants.LinkToCategory)?.EntitySystemId.MapTo<Category>().MapTo<LinkModel>();
if (!string.IsNullOrEmpty(linkToCategory?.Href))
{
return linkToCategory.Href;
}
Thank you! works great now!
Nice to have theory, I learned allot
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.