Portal Engine
Version 3.x > Portal Engine > Portal Page Macro Evaluation Problem View modes: 
User avatar
Member
Member
mcutter-global-id-group - 10/16/2008 1:26:08 PM
   
Portal Page Macro Evaluation Problem
We have a site that wanted to put different images opposite the logo at the top of each page.
The zoneLogo div in the master page template is as follows:
<div class="zoneLogo">
<cc1:CMSWebPartZone ID="zoneLogo" runat="server" />
<img src="/getfile/<img src="/getfile/32b6285a-c061-420f-b77c-d8fd555096a2/top_cereal.aspx" style="float: right" />
</div>

The question is how to parameterize the background image so that it can be easily changed on each page?
Tech support was helpful in pointing me to the Developers Guide Appendix A which describes how to use macros to paramaterize html elements.
The matrix at the bottom shows that page layout needs to be resolved in .Net.

First step is to add a zoneTopImage attribute to sitemanager/dev/doctypes/page (menu item)/fields.
Attribute type is text and field type is Image Selection.
This field can then be edited on the form tab of each page using the image selector.

Second step is to parameterize the <img> tag with this field.
After trying a few different things and looking at the html that gets rendered, I found the following works.
<img src="/getfile/<%=CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("{%zoneTopImage%}")%>/foo.aspx" style="float: right">
Note that it doesn’t matter what is put in for "foo", as long as it is not empty and is followed by .aspx.
Tech support confirmed that the /getfile path resolves based on the guid and "foo" is ignored.

However, it appears that the zoneTopImage attribute I added to pageMenuItem.fields now shows up on the form tab of all pages in all sites.
So I tried creating a topImage document type that is only available for this site as described in DevGuide/DocTypes and Transformations.
I then added a topImage doctype to the home page and set the zonetopimage field. Evaluating this attribute with
<img src="<%# GetFileUrl("zoneTopImage") %>" style="float: right">
in the master template as specified in the examples throws an error when viewing the home page:
[Error loading the layout 'Layout']
http://server/CMSTemplateLayouts/...ascx(9): error CS0103: The name 'GetFileUrl' does not exist in the current context
Same thing happens for GetImage and using <%= %> tags.
The issue appears to be one in resolving the GetFileUrl or GetImage methods.

Any ideas?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/17/2008 6:08:16 AM
   
RE:Portal Page Macro Evaluation Problem
Hi,

Just to be sure - you want to have in the master page header image, that will be changed according the the document the user is on - for home page image A, for news page will be displayed image B and so on.

If yes, I think the easiest way is to use a repeater. You can set it in two ways:

1) You can upload the images as a new documents underneath every item (it is recommended to create custom doc. type for these files). The you will set the repeater's Path property to "./%" - all documents under the current document. You will also set the document types property to list only the files and also the transformation. You can use the WHERE and ORDER by condition in case there are more file documents.

2) Second option is similar to what you have already mentioned - you can add to the document type new field (DB table column) and upload the images to the documents as attachments. Then, you will use the repeater web part. You will set the path for current document - ".". In the transformation you can use function <%# GetDocumentUrl("NodeGUIDColumn", "NodeAlias") %> - where NodeGUIDColumn is the name of the field you have added recently and the node alias could be left as an empty string.


I hope it makes sense and will help you.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
mcutter-global-id-group - 10/21/2008 8:27:47 AM
   
RE:Portal Page Macro Evaluation Problem
Hi Juraj,
It sounds like you are saying that there is no way to tag fields to only show up on specified websites.

I've never tried to access doc loaded under a page, so am not sure how to fill in the blanks for what you are proposing for the repeater. I've added a repeater to the zoneLogo webpartzone in the masterpage template wth the following properties
default show for doctypes: cms.menuitem
content path: ./%
content filter doctypes
transformation: mytran

If I try to enter a transformation such as <%# GetImage("FileAttachment")%> directly then I get a transformation not found error. So I created a mytran doctype and added this transformation to it.
This almost works. The zoneLogo cmswebpartzone also has a logo editableimage in it. Here's the complete html that gets rendered to the zoneLogo <td>:
<td class="zoneLogo" colspan="2">
<img id="plcRoot_Layout_zoneLogo_EditableImage_imgImage" style="border-width: 0px;" src="/getfile/3914a773-79b9-4da0-bd83-9da85e0216bf/logo.aspx"/>
<img border="0" src="/getattachment/a4ce09d3-b9c2-4ec4-9019-135e5db66ea7/top_tomatos.aspx" alt=""/>
</td>
The problem is that I want the second image to render with a float right as follows:
<img border="0" src="/getattachment/a4ce09d3-b9c2-4ec4-9019-135e5db66ea7/top_tomatos.aspx" alt="" style="float: right"/>

How do I write this transformation to include the style? I could break the zoneTopLogo <tr> into two <td> and have a separate webpart for each one

It seems like I should be able to use an <img> tag instead of a repeater, but when I tried this in the first post it did not evaluate. Surely there must be a way to use an image tag instead of a repeater to reference an image file loaded underneath every page. How would the source be tagged?
<img src="<%# GetFileUrl("zoneTopImage") %>" style="float: right">
gives an error
CS0103: The name 'GetFileUrl' does not exist in the current context
So what is the proper way to do this?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/21/2008 9:05:14 AM
   
RE:Portal Page Macro Evaluation Problem
Hi,

I am sorry, it seems that I was not clear enough.

Please see this document about common web part properties - http://www.kentico.com/docs/devguide/common_web_part_properties_and.htm.

You can specified the "Show for document types" which means that the web part (repeater in this case) is displayed only on documents of this type. "Content filter" property is usually set to document types you want to list in the repeater (e.g.: CMS.MenuItem;CMS.File) and in the transformation you need to select some transformation that was created for some document type (http://www.kentico.com/docs/devguide/writing_transformations.htm).

In the transformation macro <%# GetImage("FileAttachment")%> the "FileAttachment" is the code name of the field that was added to appropriate document type. So, in the transformation you can use IMG elements as usual and evaluate the file attachment (if the file is uploaded to existing document type) or from the CMS.File document type.

So, my suggestions were:
1) create a new document underneath each menu item, e.g. this documet will be CMS.File type. Then you will set the repeater to list only CMS.File types and get the file from the "FileAttachment" field in the transformation code.
2)In second example, you can add new field to the CMS.MenuItem document type where you will upload the image and you can use the macro as mentioned above (GetImage) or this one: <%# GetDocumentUrl("NodeGUIDColumn", "NodeAlias") %>

I hope it makes more sense now.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
mcutter-global-id-group - 10/29/2008 10:10:59 AM
   
RE:Portal Page Macro Evaluation Problem
I'm having problems getting your proposal to work.
The original approach I took seems to work fine, but the only problem is that the fields I defined show up on all sites that use the page (menu item) docType. So I tried creating a new fcPage docType with the custom fields needed to specify images to be used. I used the same settings for ChildTypes and Transformations as were used for the page (menu item) docType, and modified root to include this docType.

When I create a new document in the site I now get the fcPage doctype. The problem is that when I select a new fcPage doctype it always gets created as Page (menu item).

What is going on???

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/29/2008 10:19:19 AM
   
RE:Portal Page Macro Evaluation Problem
Hi,

What is the value in the document Properties tab -> General -> Other Properties frame -> Type?

Could you please send us your custom document type in export package (http://www.kentico.com/docs/devguide/exporting_objects.htm) so we can inspect it?

Thank you.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
mcutter-global-id-group - 10/29/2008 10:28:08 AM
   
RE:Portal Page Macro Evaluation Problem
Properties tab -> General -> Other Properties frame -> Type
is set to page (menu item)
It should be set to fcPage, but every time I try and create a new document of type fcPage the page that gets created is of type page(menu item)
I'll send the object export via email.

BTW, you can delete the duplicate post - my browser refresh must have posted the same reply.

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 10/29/2008 4:17:51 PM
   
RE:Portal Page Macro Evaluation Problem
Hello,

You've probably replicated Page menu item very well - also with '~/cmsdesk/Content/newpage.aspx' page as a page which shows up when creating new page (based on your custom.page_foodchain doc type).

If you wish to use it, you may need to edit it and say there that you wish to create your doc type, not CMS.MenuItem. Please follow steps below.

1. Make copy of '~\CMSDesk\Content\NewPage.aspx' page. Please rename it to NewPage1.aspx

2. Please edit new '~\CMSDesk\Content\NewPage1.aspx.cs' page going to the line 70 and replace your doc type:

CMS.TreeEngine.TreeNode node = new CMS.TreeEngine.TreeNode("custom.page_foodchain", tree);

3. Please go to 'Site Manager -> Development -> Document types -> Edit(Page_Foodchain) -> General tab' and insert ~/cmsdesk/Content/newpage1.aspx to the 'New page' field.

This should enforce adding new document based on your custom.page_foodchain document type while creating new page.

Best regards
Ondrej Vasil

User avatar
Member
Member
mcutter-global-id-group - 10/30/2008 8:43:25 AM
   
RE:Portal Page Macro Evaluation Problem
Thanks, Ondrej.
This solution works well.
However, I'm surprised that the TreeNode(className) parameter you refer to in step 2 is not parameterized somewhere in the docType GUI. This is an obvious detail that is needed to make the docType mechanism fully functional. It could be implemented very simply by adding a queryString className parameter in step 3, then modifying the btnOK_Click method to use the queryString if it exists and default to CMS.MenuItem if not.
New page: "~/cmsdesk/Content/newpage1.aspx?className=custom.page_foodchain"
Alternatively you could add a ClassName field to the docType template

Could you propose this to the dev team for the next release?
Thanks

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 11/3/2008 7:43:32 AM
   
RE:Portal Page Macro Evaluation Problem
Hi,

Good point indeed. I will definitely do that. Let's see if our CTO will consider it as a new feature to be added within new release.

Thank you for your suggestion

Best Regards
Ondrej Vasil