Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Using the classname macro in Page Title Meta Feld View modes: 
User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 12/22/2011 1:47:45 PM
   
Using the classname macro in Page Title Meta Feld
I am having the hardest time making it so that I can set the page title based upon the document type.

After trying to do it with straight macros like this :
{%if(classname == "Custom.Class"){ return DocumentName + " Something"} else if(classname == "Custom.Class2"{ return "Something Else"}


This didn't really work the way I wanted it to, so I came up with a Custom Method and registered it.

I won't get into the details of what my custom method does because it isn't important for this issue.

I call my custom method like this :

//This works in the context of a web part or widget, but not in the Page Title meta field
{% ClassPageTitle(classname) %}

// I've tried using other string methods on the classsname macro that might give me the same result as SubString, but none of them work.


Basically, when used in the Page Title Meta field, the classname macro acts very strangely. I've spent several hours trying to get this to work and I am extremely frustrated.

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 12/23/2011 9:08:09 AM
   
RE:Using the classname macro in Page Title Meta Feld
I've gotten around the problem by not passing the classname as a parameter, but instead getting the classname from within my custom method from CMSContext.CurrentDocument.NodeClassName (which for some reason isn't available as a macro).

This still doesn't address the problem with the classname macro acting strangely in the Page Title meta field.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 12/27/2011 5:30:20 AM
   
RE:Using the classname macro in Page Title Meta Feld
Hi,

I tested behavior with this macro and it seems to be working correctly:

{%if (classname == "CMS.MenuItem") { "TRUE" } else { "FALSE" }%}

Best regards,
Ivana Tomanickova

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 12/28/2011 2:39:48 AM
   
RE:Using the classname macro in Page Title Meta Feld
I know it works that way, but only when you evaluate classname once.

To reproduce the issue with the classname macro and witness it yourself. Try each of these macros in the Page Title field and observe the results.

{% documentname + documentname %} This works fine
{% documentname + classname %} This gives you a blank value

{% classname %} This works fine and gives you the classname value

{% classname + classname %} This gives you a blank value

{% documentname + classname %} this only gives you only the document name

Now I hope that you can see that it does not work as expected. Please try to find out what's wrong with it. Maybe ask Martin.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 1/1/2012 9:56:23 AM
   
RE:Using the classname macro in Page Title Meta Feld
Hello,


I have reproduced the issue and forwarded it to our developers. I will let you know with news as soon as possible.


Best regards,
Helena Grulichova

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 1/3/2012 1:31:14 AM
   
RE:Using the classname macro in Page Title Meta Feld
Hello,


there was a bug with the Page title field and that is why it processed the macros improperly. We will fix it in the 6.0.12 hotfix. The workaround is that it is possible to use two simple macros instead of one macro with two expressions joined by +. However, thank you for your report. You will get a tree for this bug:-)


Best regards,
Helena Grulichova

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 1/3/2012 12:11:46 PM
   
RE:Using the classname macro in Page Title Meta Feld
Thank you for your help.

In response to your suggestion "The workaround is that it is possible to use two simple macros instead of one macro with two expressions joined by +" That would be a solution for the examples I gave you to instruct you how to reproduce the error, but not a solution to the problem I was having. I wanted to pass the classname to a custom method, which wouldn't work because it would always be null. I believe that the hotfix will address this issue as well.

Thank you again for your help, it is much appreciated.