Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Display custom document in webpart View modes: 
User avatar
Member
Member
ajlisowski-live - 10/23/2013 4:23:46 PM
   
Display custom document in webpart
Hey guys, relatively new kentico user, first time poster. Right now I am tasked with the following assignment:

I need to create "dropzones" on certain pages where customized, dynamic content will appear depending on certain paramaters in the url.

So for a rough example, lets say I had a welcome page. I would have a section of the page that could show you a default message or a specialized message if you had referer=google in the URL. Now the tricky part is, we dont want to limit these dropzones to just text, we would want to pretty much allow the content that goes into these areas to be customized just as our pages are.

To this end, I made a custom document type, and a custom web part that looks at the parameter sin the url, the paramaters given to the webpart itself, and then fetches the custom documents that should be rendered.

The issue is, I want to render the document fully, as though the user went to the path of the document. I want to display the template for the document, any webparts assigned to the document etc. So far all I can do currently is render out the documents fields with transformations in a repeater, or viewer or whatever.

I am hoping I am missing something that will allow me to just tell kentico to render the document using the template assigned to it. Any ideas?

User avatar
Kentico Support
Kentico Support
kentico_janh - 10/24/2013 1:53:18 AM
   
RE:Display custom document in webpart
Hello,

I am not sure I completely understand your request, however any querystring in the url can be taken and used as a querystring macro like {%referer%} or {%QueryString.GetValue["referer"]%} and decide what to render on the page by redirecting your visitor according to a value in this macro or displaying a specific web part/zone, etc., so please describe some real scenarios and I'll try to find out a proper solution for you.

Best regards,
Jan Hermann

User avatar
Member
Member
ajlisowski-live - 10/24/2013 10:02:47 AM
   
RE:Display custom document in webpart
Basically I want to render a specific document on a page, not using transitions to display the various fields of the documents, but to display the content of the document using the template assigned to that document.

So, I have a custom document called LandingPageContent this has 3 fields:

Paramater:
Value:
Zone:

It has a template called LandingPageTemplate which right now just consists of an editable text area, but realistically I would like our designers to be able to customize this however they want, they way they customize our pages (add zones,webparts etc). Maybe use ad-hoc templates on some "LandingPageContent" documents. Etc.

I have a webpart also called LandingPageContent that has a field of "Zone". If I put this webpart on a page it searches for any documents that match the Zone that have a paramater in the URL with a matching value.

So I saved a LandingPageContent Document with

Paramater: referer
Value: Google
Zone: Left

And in the template I typed in the editable text area "This is the left content."


Then to an existing page I added a landingPageContent webpart with a zone=left to a page.

If a user hits that pages with ?referer=Google the webpart will find that document. So far, so good.

My problem is I want to render this document as it would be rendered by the template assigned to it. Right now all I can do is render the template using some transitions or with an itemtemplate binding its properties. So I could render out

"Referer Google Left"

But want I want to render (just in this area of the page) is what the user would have seen if they had navigated to the path of the document and let the template render the document. So, right now it would just say "This is the left content" Does that clearify things?

User avatar
Member
Member
ajlisowski-live - 10/24/2013 4:24:51 PM
   
RE:Display custom document in webpart
So it looks like pageplaceholder's do exactly what I am looking for, you tell it what document to display and whammy, it uses the document's template to display it. So I suppose my question becomes, is it possible to dynamically add pageplaceholders to a page onload, then point said placeholder at a document to render it?

User avatar
Member
Member
ajlisowski-live - 10/24/2013 4:55:30 PM
   
RE:Display custom document in webpart
For now, I simply have a pageplacehlder in my webpart and the pageload of the webpart finds a matching document and puts it in the pageplaceholder. This means only one document can go in each content rather than allowing it to show all matches. But I think this actually fits the buisness requirements better. Id still like to be able to add the placeholders dynamically but right now I am unsure how to do so.

At least I learned a lot about kentico scrambling around for far more complicated solutions to this requirement.

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/6/2013 1:30:37 AM
   
RE:Display custom document in webpart
Hello,

Usually, if the implementation is difficult enough, the approach is probably not the right one.

If you need to render anything repeatedly you can take advantage of transformations (in repeaters or just in any static text using the ApplyTransformation method). I'll give you an example:

Let's say you have some landing documents with following properties:
Document 1
- Value: Google
- Zone: Left

Document 2
- Value: Google
- Zone: Right

Document 3
- Value: Bing
- Zone: Left

Document 4
- Value: Bing
- Zone: Left

Now you can place a repeater to your left zone, set its parameters to select all landing page and specify the Where condition property as below:
Value = {%referer%} AND Zone = 'Left'

Now you get all documents which belongs to the Left zone and matches a referer from the query string.

You can do the same with the right zone:
Value = {%referer%} AND Zone = 'Right'

Best regards,
Jan Hermann

User avatar
Member
Member
ajlisowski-live - 11/6/2013 11:43:55 AM
   
RE:Display custom document in webpart
Well getting the documents was never an issue. But in a repeater, how would I go about displaying the contents of the documents using the template associated with that document?

Like for example, one of my documents contains an adhoc template with a webparts section that has a bing maps webpart. So I would want to, if the url param and zone match, render that bing map.

I do not believe I can do so with transformations, correct?

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/7/2013 1:17:44 AM
   
RE:Display custom document in webpart
Hello,

Ok, so you practically need to render the entire page with all web part zones and with the entire content of given document and its template right? In this case I would use the repeater as well with the same configuration as described above, but in the transformation I would render an iframe with the target of given document or one of alternative approaches:

http://stackoverflow.com/questions/1629897/substitute-to-iframe

Best regards,
Jan Hermann

User avatar
Member
Member
ajlisowski-live - 11/8/2013 9:53:42 AM
   
RE:Display custom document in webpart
I wanted to avoid an iframe, but using ajax to load in the document might not be a terrible solution. It just is a bit frustrating because pageplaceholders with the path set to the document render it as I want, and it would be nice to be able to put those in the transformation. I suppose divs with jquery .load works decently enough as well.

For now the currently customwebpart that simply uses a single pageplaceholder meets the business requirement and is simple and uncomplex enough to feel like it isnt hacky. If the requirements change and I need to show multiple matches I will likely switch to a repeater with a transformation of the div with ajax population of the document. Thanks for your help.