Liferay Custom field from web content in velocity template - liferay

I need to set some custom tag in portal_normal.vm which define in each Web Content.
My case:
Go to Control Panel --> custom Field --> web content
Create a new custom field called "custom_metas"
Put this code in portal_normal.vm <meta property="og:title" content="$themeDisplay.getScopeGroup().getExpandoBridge().getAttribute('custom_metas')" />
This code only works if custom field is created in site (not in web content). When I create in web content show as plain text.
In my portal-ext.properties put:
journal.template.velocity.restricted.variables=
Nothing change.
Finally I try this solution given in liferay forums but doesn't work. Notice: $reserved-article-id.data doesn't print nothing.
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
#set ($ja = $journalArticleLocalService.getArticle($getterUtil.getLong($groupId),$getterUtil.getString($reserved-article-id.data)))
#set ($resourceprimKey = $ja.getResourcePrimKey())
#set ($assetEntryLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService"))
#set ($assetEntry = $assetEntryLocalService.getEntry("com.liferay.portlet.journal.model.JournalArticle", $resourceprimKey))
#set($JournalArticleResourceLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleResourceLocalService"))
#set ($journalArticleResource = $JournalArticleResourceLocalService.getArticleResource($assetEntry.getClassPK()))
#set($JournalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
#set ($journalArticle = $JournalArticleLocalService.getArticle($getterUtil.getLong($groupId), "$journalArticleResource.getArticleId()"))
#set ($custom = $journalArticle.getExpandoBridge().getAttribute("custom_metas"))
$custom display as plain text

You are confusing theme templates with web content templates. In a theme template you have neither a single attached web content article, nor do you have access to any web content specific variable like $reserved-article-id.
And you mix up pages and portlets. Your web content article is attached to a portlet on your page - and as you can have more than one portlet with a web content article on a page, you don't have the article that is loaded.
But if you attach a tag to your webcontent (not a custom field - just a tag in the Categorization section), that tag will be added to <meta name="keywords"> in the head automatically.
If you need the tags somewhere else - they are stored in the request attribute WebKeys.PAGE_KEYWORDS (= "LIFERAY_SHARED_PAGE_KEYWORDS").

Related

How to have H1 and byline in the master page - Kentico

I'm trying to work out a way I can add my H1 and byline markup to my Root master page and then have all the pages underneath fill these fields in. I'm using the Portal Engine development mode.
The H1 and byline are in a different web part zone to the page placeholder. They are showing on all the pages under my root node but I can't find a way to make populate the title or byline on those pages.
I've tried a few things:
- editable text web part - but this is only editable on the Root node and not the pages underneath
- I thought maybe I could use <%# Eval("Byline" %> and add this as a field to the Page type but that doesn't show through either.
Is there any way to include something in the master page that is dynamically filled in (or editable in the designer) on all pages under the root node? Or do I need to move myH1 and byline out of the master page and include in every template that my pages use?
You can add additional field to your page type named 'Byline'. This field will be editable on Form tab of each page. Then you can include some viewer web part like Document Viewer or repeater. Then configure Path like './' (it means to display information for current page). And add transformation where you cat do something like <%# Eval("Byline") %>.
Or alternative way is to use static html web part and add macro there {%CurrentDocument.Byline%}.
You can do it using macros: add a static text web part on your master and set text property to :
<h1>{%CurrentDocument.DocumentPageTitle#%}</h1>
or
<h1>{%CurrentDocument.DocumentName#%}</h1>
depending on where you keep your page title.

MODX - Template Variable for Particular Page

I have one MainTemplate shared with pages like : home,about-us,contact-us
I also have template variable to control all pages' : meta description, og title, og image, og desc
I created a Template Variable Home Page Banner link to my MainTemplate to upload images just for Home Page, but when i click other resources, this Home Page Banner Template Variable will show up also.
Any method that makes Home Page Banner TV shows up on home resources only?
Is it duplicate another template from MainTemplate named as HomeTemplate for Home Page Banner TV only?
Personally I felt this way is abit dangerous for future maintanance.
May I know any more method to achieve this?
Tq.
For "Home Page Banner" it is better to use http://modx.com/extras/package/bannery (docs - https://rtfm.modx.com/extras/revo/bannery)
I think it will be more complicated than a home-page-banner in main-template, but... If you really want to have the same html on multiple templates, simply create common chunk with your html, e.g.:
<html>
<head>
<title>[[++site_name]] - [[*pagetitle]]</title>
<base href="[[++site_url]]" />
</head>
<body>
[[*content]]
</body>
</html>
and in your templates (home-template and main-template) instead of html use only this:
[[$your-chunk-name]]
Then you can add a home-page-banner only to the home-template.
Sounds like you have the Template Variable set to show up in both your Main Template and your Home Template. Your TV should just be set to show up on the Homepage Template which you set under Your TV > Template Access and then untick the Main Template checkbox.
As mwl says - is long as you keep your templates simple (i.e. you use Chunks and Snippets wisely) having lots of templates isn't a bad thing on a MODX site.

Disable borders in Web Content Display via template

I'm creating a set of custom structures (and matching templates) for Web Content Displays on a Liferay site.
To make things more convenient for site maintainers, I would like one of these templates to suppress look-and-feel borders by default.
I've found documentation and samples online showing how to disable borders for portlets that are embedded in the theme, but I haven't had any luck applying those techniques inside a WCD template.
Here's the code I've seen embedded in a theme:
#set ($VOID = $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false"))
#set ($VOID = $theme.runtime("customportletname_WAR_pluginname", "", $velocityPortletPreferences.toString()))
$velocityPortletPreferences.reset()
Here is how I've applied it to my template:
#set ($VOID = $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false"))
<div class="custom-wcd wcdnormal">
<h2>$title.getData()</h2>
$content.getData()
</div>
$velocityPortletPreferences.reset()
I'm not surprised that it didn't work -- there's nothing analogous to the $theme.runtime call that applies the prefs to a portlet, but I also don't know whether $theme.runtime is appropriate at this layer, and if it is, what value to supply as the first argument. I suspect this last is the most likely alternative, but I don't know how to identify the WCD portlet to $theme.runtime, nor do I know how to track that information down (I'm not a Java dev by any stretch).
And just to clarify: it is not acceptable to disable borders on all portlets by default, nor am I in a position to modify the Java controller that consumes journal-article components at render-time.
Any advice is appreciated.
Simple and direct:
$velocityPortletPreferences.setValue("portletSetupShowBorders", "false")
$velocityPortletPreferences.setValue("languageIds", "pt_BR,en_US")
$velocityPortletPreferences.setValue("displayStyle", "1")
$theme.runtime("82", "", $velocityPortletPreferences.toString())
$velocityPortletPreferences.reset()
This example is for embed the language portlet (Portlet ID = 82), direct in one of .vm theme files, in my case this code is on navigation.vm.
Liferay property/preference names have a tendency to change sometimes. I created a hook this week to create a site, populate it with pages containing portlets and also to provision the CMS with a default set of structures, templates and articles. I too had to turn off the borders for my portlets and needed to set the following preference name to false to achieve that: portletSetupShowBorders
I java code it did this as follows:
PortletPreferences prefs = PortletPreferencesFactoryUtil.getLayoutPortletSetup(page, portletInstanceId);
prefs.setValue("groupId", String.valueOf(page.getGroupId()));
prefs.setValue("articleId", article.name());
prefs.setValue("portletSetupShowBorders", "false");
prefs.store();
From a Liferay Journal Template you should be able to use the following code to turn of the borders of the portlet that will show an article that uses the template:
#set ($portletPreferencesService = $serviceLocator.findService('com.liferay.portal.service.PortletPreferencesLocalService'))
#set ($companyId = $getterUtil.getLong($companyId))
#set ($ownerId = 0) ## PortletKeys.PREFS_OWNER_ID_DEFAULT
#set ($ownerType = 3) ## PortletKeys.PREFS_OWNER_TYPE_LAYOUT
#set ($plid = $getterUtil.getLong($request.theme-display.plid))
#set ($portletId = $request.theme-display.portlet-display.id)
#set ($portletPreferences = $portletPreferencesService.getPreferences($companyId, $ownerId, $ownerType, $plid, $portletId))
#set ($VOID = $portletPreferences.setValue('portlet-setup-show-borders', 'false'))
#set ($VOID = $portletPreferences.store())
Just remember that you also need to add the following line to your portal-ext.properties:
journal.template.velocity.restricted.variables=

How to change teamsite text layout programmatically?

I have a code that creates a teamsite. After that I add some web parts to wiki web part zone(rich content area). In SharePoint 2010 user can change a text layout of the rich content in page edit mode.
Is there any way to programmatically change the text layout of the rich text area? I would want to set "two columns with header"-layout after site creation has completed.
My site is created like this.
site = elevatedSite.SelfServiceCreateSite(params.....);
rootWeb = site.RootWeb;
rootWeb.ApplyWebTemplate("STS#0");
SPListItem currentItem = rootWeb.Item;
var xhtml = currentItem[SPBuiltInFieldId.WikiField] as string;
Now I can modify the xhtml string and save it back to the page. I have tried to change it so that it contains exatly the same html structure which have created by sharepoint itself, when changing the text layout. After that change, actually it is not recognized as "two columns with header"-layout in sharepoint. It is still default one-column layout. Is there anybody who knows is it possible to change the text layout of the rich text area programmatically?
I found answer from here http://donalconlon.wordpress.com/2010/05/04/sp2010-creating-a-wiki-page-using-the-om/. SharePoint stores the information about used layout to the hidden span-element in wiki page.
For example, this presents two column layout without the header or footer.
<span id="layoutsData" style="display: none">false,false,2</span>
first false = no header
second false = no footer
2 = two columns
I have been looking for some information on doing the same thing. I found this blog post that checks out the page, edits the content then publish and approves it.
SharePoint 2010 change page content data through Object Model / API – Console Application
If you need to modify pure HTML content, its better to use cutom IHttpHandler (wrapped in dll) and connect it to SharePoint via web.config. Is is also allowing to modify dynamic content like AJAX responses.

Need to have separate "complete" Drupal theme for each page on a site

I want to build a Drupal demonstration site where I can create several custom themes and display each on a separate page of the site. Access can be either via links or menu items. The "simpler" the solution the better.
Create a custom block that executes PHP code. The following code snippet should show the current page in the theme set in $custom_theme.
global $custom_theme, $theme;
// If $theme is set, init_theme() will not initialize the custom theme.
unset($theme);
// Set the theme you want to use.
$custom_theme = "garland";
init_theme();
There is also a module that allows you to change the used theme based on some rules (in example, the content type being showed, the URL of the page being viewed, etc): the project page is http://drupal.org/project/themekey.

Resources