From a 2sxc App View, is there a way to Render another Entity + View in a single method? - 2sxc

I am aware of the Inner-Content/Content-Blocks stuff you have made available via Content-Type setup of a WYSYWIG and related fields. However, what I am looking for is much simpler, seems possible, but for some reason I am not finding it based on how I have searched so far. Let's say I am already in a View outputting my Content-Type, a "Destination" which ties together Basic Content, Image(s), and a Location. I have a field in the Destinations content-type that is a simple 1:1 to an Entity Location. And yes, I am working in the Content-App. The custom Location View already exists to output the linked Entity by itself. Easy to just add another Content module to the page, but we don't want to do that. What I am looking for is to output that whole View for that one linked Location Entity with a single line of code. Does this exist? I could probably use RenderPage() and pass in my Entity and rewrite the existing View to dynamically handle the passed in Entity (or default to Content as it is now).
So to rephrase, is there a function, API call, that lets me...
#...ContentBlocks.Render.View(contentEntityId, viewEntityId);

Some background
The ContentBlocks.Render requires a lot of information to work, because it also does a lot behind the scenes. So internally a content-block is a special entity which points to an app-id, a template-id and (zero, one or many) content items. So it's basically a module-definition (each module points to a content-block).
What you need
Since your entity is only the data, it can't know how it should be displayed without you specifying the template. So RenderPage is the way to go. I recommend you do this:
a sub-view which contains the whole logic and can only be used from RenderPage
call it from this view
and also call it from the other view, which contained the original work
This is better than a template which does some kind of automatic fall back, because as time goes on, people forget that it has 2 purposes, and will make changes and only test one scenario, breaking the other.

Related

Kentico Web Part Zone(s) generated by Transformations

I am using a Repeater web part in Kentico to pick out pages from the content tree, to generate nicely repeatable snippets of structured HTML, based on an ASCX transformation. (No surprises here - its been working great!).
However, a new requirement landed whereby alongside the existing HTML structure mentioned above, each repeated item must also have an area where we can add any amount of additional content; based on other web parts.
I have previously written a few "layout" type web parts; implementing CMSAbstractLayoutWebPart, as described here, which has allowed me to generate a repeating amount of web part zones, so I feel like I'm half way there. The issue with that though is that as it stands, I don't seem to be able to make use of the great power and flexibility of the transformations on the page type (which I really think I need to do, and seems like it should be possible..).
I thought I may be able to specify the WebPartZone control in the transformation markup directly, like in the following:
<%# Register Src="~/CMSInlineControls/WebPartZone.ascx" TagName="CMSWebPartZone" TagPrefix="cms" %>
<cms:CMSWebPartZone ZoneID="ZoneIDHere" runat="server" />
<div>
<h3><%# Eval("Heading") %></h3>
<p><%# Eval("Summary") %></p>
</div>
But the design view doesn't seem to pick up the web part zone; so I'm assuming the page lifecycle may not allow me to do this as I'd hoped.
So what I would like to know is:
Is it possible to include WebPartZone control in a transformation such that I can then bring in new web parts in Design view?
If not, what is the recommended way to go about this? (If a custom web part is the way to go, I'd like to clone the Repeater web part in the first instance, as many of its existing properties will be needed - but presumably this must still inherit from CMSAbstractLayoutWebPart?
Thanks!
Update
Good point about the editor's experience; I would definitely like to keep this as consistent as possible. The issue for me is that the requirements that drive my data structures are not always fully understood - and are certainly subject to change. Also, they are liable to vary (albeit subtly) across different products. So I've been trying to keep templates and page types more or less the same across the board, and push out the differences into page properties that drive web part config through macros. So given that the transformation approach won't work, I expect a custom web part is the right fit for me.
I shall post my findings!
I think adding a web part zone into transformation is not a right direction as web part zone should be a part of page template (not transformation) in order to utilize it.
I'd probably try to organize my content so each item you currently showing in the repeater has any number of child pages (potentially of a different type) and use something like hierarchical viewer in order to present all of them on the page. It allows using different transformation based on either page type or node level. Another advantage of this approach is that you keep editors experience consistent.
In the end, I was able to use transformation markup to specify the generation of web part zones. I went down the route of creating a custom web part that inherits from CMSAbstractLayoutWebPart, rather than using CMSRepeater web part or similar...
Here's a breakdown of things I needed to do this:
Gave the custom layout-type web part some properties with which to query the content tree, and supply them to a TreeProvider.SelectNodes() method in the web part code once it has initialised (by overriding the OnInit() method)
Gave the web part a TransformationName property so that the raw markup can be retrieved using TransformationInfoProvider.GetTransformation(this.TransformationName)
Used the markup above and resolved macros within it using each node from the node query
Example of macro resolution code (HTML transformations with macros)
protected virtual string ResolveNode(TreeNode node)
{
var resolver = this.ContextResolver.CreateChild();
resolver.AddAnonymousSourceData(node);
return resolver.ResolveMacros(rawTransformationMarkup);
}
Then I go looking for placeholder text in the transformation markup and use the methods available in the CMSAbstractLayoutWebPart parent class(es), as detailed here, to Append() the resolved markup and also call AddZone() as necessary to tap into the response string builder
Summary: The great functionality of the API allowed me to completely avoid the use of any repeater controls. I could generate web part zones as part of the layout web part usual layout generation process.
It would be nice if I could figure out how to resolve the expressions in SCRIPT tags in ASCX transformations to complete the story, but by using HTML transformations I can use the above to accomplish what I need.

Convert query parameters to "pretty urls"

I have an Episerver site with a JobDetailsPageController with a Index method that takes a jobId parameter and creates a view with some details about that job. The urls looks something like this: https://hostname/<root-depending-on-site-tree>/jobs/?jobid=44.
What I would like is having urls on the form .../jobs/manager-position-telco-44, essentiallly creating a slug of the job title and appending the id. I have done this in the past using standard ASP.NET MVC Attribute Routing on a non-Episerver site, but EpiServer has a routing of its own that I don't know too well and can't figure out.
Also, adding non-query strings after the slash consistently sends me (no surprise) to a 404 page, so I would need to somehow customise this behaviour. I need to use EpiServers standard routing to end up at the right "parent", but ignore the latter part (the pretty bit).
Is it possible to create such urls on a normal page in page tree in EpiServer? I do understand it is possible to create static routes, but this node can be moved around like any other page so I cannot avoid EpiServer.
Please see this blog post. What you're looking for is partial routing.
#johan is right, partial routing is one way of doing this. Just wanted to add other possible solutions that might or might not match your needs.
Import data as content
Instead of serving content dynamically, you could consider importing your job ads from whatever source you have directly in content tree as separate pages below particular root page. That would give you a lot benefits - pages would be cached, it would support multiple languages, editors would see content directly in EPiServer CMS, data could be adjusted manually, etc.
This would be a good solution if your data does not change often and you need to provide a way for editor to create a new job ad manually as well.
Implement you own content provider
Another way to serve your dynamic data to EPiServer is to write your own custom content provider. You can find documentation here: http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/7/Content-Providers/Content-Providers/
This solution requires more coding and is more complex, but it has some benefits as well. If one wanted, it would be possible to not just serve content from external data source, but also update that data by changing values directly in EPiServer UI.

Drupal 7 - Administration - Find node by it's field value

I'm looking for the way for the site's administrator / moderator to find / filter the list of nodes by some field custom value. Field value could be defined by radio / text / checkbox etc.
Default content listing proposes only few filters, it's not enough for sites with huge amount of custom nodes.
Use an EntityFieldQuery object, documented here:
http://api.drupal.org/api/drupal/includes--entity.inc/class/EntityFieldQuery/7
The documentation has no examples (ugh), but there's a thread here with some:
http://drupal.org/node/916776
EDIT: Ah, you're talking about administration and not actually writing a module to do it. If that's the case, use a view with exposed filters, like the other guy said. :)
Maybe it would help to use a view for it, where you set filters, so that you get the desired listing.
I had to test this, but I've just confirmed. Views in Drupal 7 can indeed filter across multiple content types w/ custom fields, and still have filters apply to those custom fields. They seem to treat the nodes w/o those custom fields as empty or null values.
So for instance, I have article and blog content types. Blog has images, article does not. I can sort or filter on the image field, even though article doesn't have it. It simply assumes the field is null or empty.
This however, may not solve your problem of having a large number of custom fields. If these are dynamic (i.e. they grow over time) you might be in trouble. If, however, they are set, and just a very large number, you could manage this.
So while there is no automatic add all fields, which I believe you mentioned in a previous post, you could feasibly search on a large variety of the fields. Even exposing fields that you don't necessarily display in the table, but can then search on. Or changing the fields you expose or display on a per page basis in the view. All from one view. And then you could export the view to bring it over to the other sites.
I was going to try and attach the exported view, but the export is rather large for inclusion in an answer, I think. Please let me know if you think I should still include it, or if you'd rather I can simply send it to you through a PM. Let me know!
EDIT: I decided to include a link to an export of the view. http://greggalante.com/sites/greggalante.com/files/cross_type_view.txt
http://drupal.org/project/search_api

Drupal : how to create a view that displays all the content-types

It may sound 'weird' but I need to have a view that lists all the content types I have.
For example i have two content types : contenttypeA, contenttypeB
I want to create a view that just displays the two content types (and show number of items of that type, but that can be done later).
For now what I did is add one content of each content type and list them but only show the 'node type'; it works well if there's at least one content but I want to display even without any content of that content type.
Any idea ?
Introducing the node_type table to Views requires a custom module and some Views API knowledge however http://drupal.org/node/1001222 will give you a head start.
Use a Customfield: PHP code field and custom code the whole thing with PHP. This is provided by the Views Custom Field module.
Use the Table Wizard module to make the node_type table available to views. You may need to use the Data module as well since they say that all future development is going there.
Expose the node_type table yourself by writing a custom module using the Views API as suggested by chx.
Number one is the quick and dirty way, but number 2 might be a little more manageable, but I am not completely sure it will do everything you want. If you do number 3 make sure you contribute back to the community by putting your module on drupal.org.
There is no native functionality in Views to do that. You can write a static page or (overkill) a module that provide a "system"-like type similar to Views Watchdog.

Filter a view by user-created tags in Drupal?

I'd like to add a block to the user profile that shows them content listings in their groups based on tags that they have in their profile.
(ie: someone puts a bike up for sale, the user has listed "bike" on their wishlist, it should show up to get their attention)
Since these tags vary user-to-user, I'm not sure exactly how to set up the filter.
Going a little farther, can I sort them by the number of matching tags?
I've found that taxonomy terms and views can be very tricky to get right. The main problems is that taxonomy terms has a one to many relationship with nodes, and views is built to be generic.
It might be quicker to create such a block in a custom module instead, because you may very well get stuck in views before getting what you want. Also you most likely have to create your own sort plugin for views, to get the sorting you want. I haven't seen any module creating something like that, and I don't think it's possible with views core. Creating plugin for views can be very harry, the first time you do it, so unless you know your way around views, I think you will have more luck just creating a block yourself. It's much simpler, than having to extend the views functionality.
Have you looked into Views? You can set up a block with views that retrieves (almost) ANY information from the database.
In your case, you can filter the information that you need and that belongs to the current user, also, sorting is doable via the Views administration.

Resources