Kentico 12: detect if an editable area contains any widgets - kentico

I'm building a site in Kentico 12 MVC and working on setting up content personalization. The normal way to do this is to add an editable area in the view:
<div>
#Html.Kentico().EditableArea("area1")
</div>
Then, in the CMS, the Page tab will show an empty area where the user can add a widget with personalized content.
The problem is that the content I want to personalize is located in my site's login box, which is a common element on every page, so I'd need to manually add a widget into the editable area on every page individually. But my site has over 300 pages, so that's totally impractical.
Is there a way from within my view model that I could check if the editable area has any widgets, and if it doesn't, output default content instead? I'm trying to see if there's an API method or something that would let me count the number of widgets inside an editable area, but I can't find anything in the documentation.

I guess you need to check with regex if Editable area html contains widget tag "<object type="widget" >"

Related

Template to provide static HTML wrapping a page-specific value

I am creating a page template. Each page using the template will have a single unique value that gets embedded into the page HTML. The rest of the HTML is constant for all pages. Assume the following is the desired result:
click me
I want a template that provides click me, while allowing the individual pages (content admins) to provide id.
I've tried using an Editable Text web part, and putting the "before" and "after" HTML in the HTML Envelope before and after sections, and adding the ID on the "Page" tab. However, that is not quite working. What is the best way to accomplish this?
This can be done. What you'd want to do is add that field to the page type fields you're adding those pages with. For instance, say you have a list of locations under /locations.
i.e.:
/location/chicago
/location/new-york
/location/minneapolis
The locations themselves (Chicago, New York, Minneapolis) are your custom page type and have a unique field called LocationID. On your template, add a static text webpart (not static HTML because the WYSIWYG editor overwrites the markup you add) and simply add this:
click me
If the LocationID field has a exists AND has a value, it will output it, otherwise it will just leave the URL http://www.example.com/
If you didn't want to show that link at all on other pages, then set the Show for page types property based on the page type you want it to show for in the Visibility section of the static text webpart.

Orchard Custom Theme - Create 2 additional navigation menus, only visible on certain pages

I have a custom themed orchard site - I am new to Orchard.
All pages have the same header with primary navigation, and footer. I have set header & footer up as Zones.
There are 4 main sections, 2 require a second navigation on the left; Information & FAQ.
I would like to dynamically create pages for those sections in the CMS - and have the page added to the appropriate second navigation menu, then when clicked navigate to that page (showing the correct navigation menu on the left - with the right styling for the rest of the page).
In simple steps what's the best way to do this - and does it need me to edit the Layout or other files in Visual Studio (I can if required).
I have found several articles on this online - but they all apply to completed themes, not one being created from scratch.
(I also don't have this 'map' of the site on the widgets page - how / should I create one somehow?):
Thanks.
As i understood what you are after is creating a Widget. Basically to show any content in your page you must create appropriate ContentType and attach required parts to it , and to display it you must enter url of that content in browser's address bar or click in a link for that content which in either case it will navigate to a new page and will display content inside [Content] Zone. but if you want to display a Content in a special Zone and special pages, Creating a Widget is the way to go.to create a widget the only thing required is to add a WidgetPart to it and give it Stereotype of 'Widget'.you can do this by making following changes in Migration file for your desired ContentType :
ContentDefinitionManager.AlterTypeDefinition("MyType", cfg => cfg
.WithPart("WidgetPart")
.WithPart("CommonPart")
.WithSetting("Stereotype", "Widget"));
this will turn your Content Type into a widget which can be placed in any Zone you want.
to add your widget to a Zone navigate to widgets from dashboard.
and then select the zone which you want to place your widget in :
and then select your widget
and finally select the layer in which your widget will be shown.a layer is set of rules which determine in which pages your widget will be displayed.for example selecting homepage will display your widget only in home page, selecting default will display your widget in all pages and so on.to define your own rule check here.
Edit :
to create new zone in your theme just include the Zone name in theme.txt file then open up Layout.cshtml (one resides in your custom theme's view directory) , and do following :
given your zone name is SecondaryNavigation then add following code inside your theme
#if (Model.SecondaryNavigation != null)
{
<div id="secondary-navigation" class="group">
<div class="inner">
#Zone(Model.SecondaryNavigation)
</div>
</div>
}
with this an additional Zone will be displayed in zone list and then you can put your widget inside your newly created zone.and about that picture you asked about.it is an image file which created by author of the theme and named 'Theme.png' and will displayed as a preview in manage widget screen , you can create it for your own theme and put it in your theme view directory.
EDIT 2
The migration file itself is not important.the only thing which is important is to define a class which drives from DataMigrationImpl , orchar will pick your migration file and run it automatically , migration file has firstly a Create method which returns 1 , and for each further update you must define a method called UpdateFromN in which N is current version your module is in, that will return 2 , 3 , ... what you can do in a migration file is creating database tables , creating ContentTypes , ContentParts , ContentFields , etc. there is already couple of modules shipped with orchard , check them and get the idea.

Orchard CMS - Text visible on every page & editable in CMS

I would like to add in the top right of every page - contact phone & email link.
They are styled uniquely on the page by CSS - based on their containing DIV's class.
What is the best practice way to make that visible on every page - and editable in the CMS?
Would I have to have the HTML markup editable too (the client is non technical)?
Thanks.
You want to add a HTML widget on the default layer. You can give it custom classes etc. and style it within your theme.

Default content editor in list form doesn't allow image alignment

I need to be able to adjust the alignment of an image in an "Enhanced Rich Text Field" in an announcements list in MOSS 2007. However, the default content editor in the edit form for the list doesn't provide a way to do that. What's the fastest way for me to make sure users can align images? My first thought was to customize the DispForm.aspx and EditForm.aspx pages, but they just have the ListForm web part in the content region and as far as I know, you can't customize the ListForm web part from the designer.
You can't customize the LisForm web part, but you can add a "custom list form" to create a custom edit form. Maybe you haven't seen this article: http://weblogs.asp.net/jan/archive/2006/11/06/Custom-Edit-Forms-for-SharePoint-2007-Lists.aspx
Then you could do some javascript hackery to insert your own button which then calls something similar to existing RTE_InsertImage function to call a pop-up window and do whatever you need (you'll find this function in 12\template\layouts\1033\form.js)
I fail to see (or understand) your issue. I created a new announcements list, created a new item, inserted an image, aligned it to the right, viewed the item and it worked.
Then I proceeded to create a new custom column, choose multiple lines,enhanced rich text field, edited my list item, added an image, centered it, viewed and it was also working.
The only thing I noticed is that the "rich" control does not appears on non-IE browsers.

SharePoint: Site Layouts

Hi I was wondering which Layout I could use to get the search box in the top right hand corner. I used (Welcome Page) Blank Web Part Page) as the page layout but its missing the search box in the top right corner.
Also another question: How can I add my own layouts to the list in the Create Page, page. Thank you.
The search box is defined in your master page. Ususally default.master, it would not matter which layout you choose the elements defined in the master page will still be in the same place. In your case it would appear that the search box does not exist on your master and would need to be added in again.
You would need to amend the master page for your site and add the appropriate SP control for search into the appropriate place on your page. This will ensure that a SP search box is rendered in that location for every page.
To define your own page layout have a look at Link 1 and Link 2.
As for the search box, it is defined as part of the Site Template. Try creating a Site using the Collaboration Site template.

Resources