How to display Link to Page fields properly in Liferay Dynamic Data Lists? - liferay-6

The context
I am trying to create a link list portlet on a page in my Liferay 6.2 instance. To achieve this, I have put a new Dynamic Data List Display portlet on the page and made a Data Definition that contains a Link to Page (it used to be called Link to Layout before 6.2) field. I am trying to build a custom Display Template using Liferay's guide to display an HTML unordered list with the links, but I cannot find any information regarding how to handle Link to Page field properly.
The question
How can I create a Freemarker template that displays the Link to Page field so that the href attribute contains the smart url of the page and the link text is the localized name of the page?

The Display Template editor adds the following code to the Freemarker script when you click your field:
<a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("Link_to_Page1632", locale), cur_record.getFieldType("Link_to_Page1632"))}">
Link to Page
</a>
This is a good hint to start displaying the links, just add the small details:
<#-- The record service to retrieve the list of records in this Dynamic Data List -->
<#assign DDLRecordLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService")>
<#-- The layout service that helps determine the name of the page -->
<#assign layoutService = serviceLocator.findService("com.liferay.portal.service.LayoutService")>
<#-- Get the records in the Dynamic Data List -->
<#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id)>
<ul>
<#if records?has_content>
<#list records as cur_record>
<li>
<#-- Use the snippet provided by the editor -->
<a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("Link_to_Page1632", locale), cur_record.getFieldType("Link_to_Page1632"))}">
<#-- Get the name of the page with layoutService.getLayoutName() using a temporary JSON object -->
<#assign jsonObj = jsonFactoryUtil.createJSONObject(cur_record.getFieldValue("Link_to_Page1632"))>
${layoutService.getLayoutName(jsonObj.getLong("groupId"), jsonObj.getBoolean("privateLayout"), jsonObj.getLong("layoutId"), localeUtil.toLanguageId(locale))}
</a>
</li>
</#list>
</#if>
</ul>

Related

React - Unknown prop `page_id` on <div> tag. Remove this prop from the element

I'm integrating Facebook's Customer Chat Plugin to my website. In the instructions it says:
include a div with the following attributes in your HTML:
<div class="fb-customerchat"
page_id="<PAGE_ID>"
ref="<OPTIONAL_WEBHOOK_PARAM>">
</div>
When I did so (this is the React version) :
<div className="fb-customerchat"
page_id="<PAGE_ID>"
ref="<OPTIONAL_WEBHOOK_PARAM>">
</div>
... I got this error from React: Warning: Unknown proppage_idon <div> tag. Remove this prop from the element. For details, see https://reactjs.org/warnings/unknown-prop.html, and the customer chat plugin isn't shown at all (I can still find the HTML elements in the DOM tree).
I did some searching and it seems like React doesn't recognize the custom page_id attribute. I tried changing it to data-page_id but it doesn't help.
Have anyone encountered the same problem and how did you resolve it ?
https://react-cn.github.io/react/docs/tags-and-attributes.html
Looks like page id is not supported. Try using classID or just id
I found out that the Customer Chat Plugin needs an HTML element inserted into the DOM with the parameters specified. With React, you're never passing in raw HTML, hence the error message. To resolve this, you can do either:
- insert the .fb-customerchat div directly to your HTML or
- use this package: https://github.com/Yoctol/react-messenger-customer-chat which is a workaround for React

RDFa OfferCatalog Syntax

I have been trying to find the best way to link two items together using RDFa, specifically linking a Person to multiple SoftwareApplication entries.
The way I currently do this on the author page is:
<div class="container text-center" vocab="http://schema.org/" typeof="Person">
...
<span property="hasOfferCatalog" typeof="OfferCatalog">
<meta property="numberOfItems" content="10" />
<span property="itemListElement" typeof="CreativeWork">
<meta property="name" content="Project Name" />
<meta property="url" content="https://www.my-domain.tld/ProjectName/" />
</span>
...
As above the project is actually a SoftwareApplication, and the URL has a complete RDFa/Schema.org definition of it, but if i put:
typeof="SoftwareApplication"
on the author's page then, kind of expectedly, Google's Structured Markup validator throws errors about required values not being present for it, CreativeWork throws no errors but is less specific. I don't really want to repeat the entire SoftwareApplication metadata everywhere the project is referenced, I'd rather just say "go look at this URL".
What is the correct/best way to cross reference the SoftwareApplication pages from the author page? in the project the reverse reference is easy as there is an Author attribute, which can be of type Person, which is acceptable with just name and URL.
Once I know the correct RDFa way of referencing I'll apply the tags to content in the page rather than using meta tags.
To link items together, you need a suitable property. Like author (to state which Person is the creator of the SoftwareApplication), or like hasOfferCatalog (to state which SoftwareApplication is offered by the Person).
Inverse properties
In most cases, Schema.org defines its properties only for one direction. So there is only author, and no authorOf. If you need the property for the other direction, you can use RDFa’s rev attribute.
Linking instead of repeating
If you don’t want to repeat your data (i.e., only define it once and link/refer to this definition instead), you can provide a URL value. Schema.org allows this for all properties, even if URL is not listed as expected type. If you want to follow Semantic Web best practices, give your entities URLs (as identifiers) with RDFa’s resource attribute, and use these URLs as property values to refer to the entities.
For this, simply use one of the linking elements (e.g., elements with href or src attribute).
Example
Using the author case as example:
<!-- on the page about the software: /software/5 -->
<div typeof="schema:SoftwareApplication" resource="/software/5#this">
Author:
<a property="schema:author" typeof="schema:Person" href="/persons/alice#i">Alice</a>
</div>
<!-- on the page about the person: /persons/alice -->
<div typeof="schema:Person" resource="/persons/alice#i">
Authored by:
<a rev="schema:author" typeof="schema:SoftwareApplication" href="/software/5#this">Software 5</a>
</div>
Errors in Google’s SDTT
If the Structured Data Testing Tool gives errors about missing properties, note that it doesn’t mean that something is wrong with your markup. Schema.org never requires a property.
It just means that these properties are required for getting a certain Google search feature. So ignore these errors if you don’t want to get the feature (or if you can’t provide all required properties).
Thank you for the other response, I'll have a read over the linked resources, I have also found a solution to the specific case in my question.
Google Search Console has a page on Carousels which shows that you can use ListItem, which only "needs" URL, to populate the hasOfferCatalog property. E.g.
<span property="itemListElement" typeof="ListItem">
<meta property="position" content="1" />
<meta property="url" content="https://www.my-domain.tld/ProjectName/" />
</span>

Build URL/Page links with Scala in Play Framework - clicking to open a new page

I am new to Scala and am trying to build an href link to another page within a website that was already built with HTML and JavaScript. All the links are set up as:
<a href="mypage.html">
I have been researching Scala and understand that it is more routing and configuration than just referring to a another page. I also understand that the other html pages seem to be used as a Single Page Application setup using the #content tag in the main.scala.html page. I may be wrong on this description, but this is how it makes sense to me.
I have set up a new Scala page and am referencing it in my HTML:
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-6 col-ss-12 margbot30">
<a class="services_item" href="#views.html.login3(loginForm)">
<p>
<b>New</b> User Account
</p> <span>Sign up for a user account</span>
</a>
</div>
It does not give me an error, but actually show that login3.scala.html page in that <div> tag. I wanted to have the text clicked and then open that page.
How do I get this link or route to work correctly?
I found this post, but I am still not sure what to do:
Play! Framework - creating simple html links
I appreciate the help and any code examples.
What "#views.html.login3(loginForm)" is doing is invoking the Scala function login3 and the resulting content is being rendered into the page.
Instead of thinking of pages linking to pages, think of pages linking to controllers.
If you have a controller like this:
package controllers;
class FooController extends Controller {
def foo = Action { request =>
Ok(views.html.foo())
}
def bar = Action { request =>
Ok(views.html.bar())
}
}
This is exposed via the routes file as
GET /foo controllers.FooController.foo
POST /bar controllers.FooController.bar
In your views, you then define your hyperlinks using the generated routing:
whatever
So in your case, instead of using
<a class="services_item" href="#views.html.login3(loginForm)">
you would instead have
<a class="services_item" href="#routes.SomeController.theFunctionThatRendersLogin3()">

Change the url for search input

I have a search form on a Drupal page (A custom view) that searches all my articles:
URL: www.site.com/articles
<form>
<input type="text" placeholder="Search Library" class="searchbox">
<button type="submit" id="edit-submit" name="op" value="Search" class="form-submit">Search</button>
</form>
When a user submits this form I get a string appended to the end of the url like this:
www.site.com/articles?search_fulltext=SEARCHTERM&op=Search
The problem is that it's not working, and to get it to work I have to search from a different page like here:
www.site.com/search?search_fulltext=SEARCHTERM&op=Search
So ultimately I would like to have my search box on a page, but when a user submits I want it to reference another url:
www.site.com/search?search_fulltext=SEARCHTERM&op=Search
I basically want to have a search box on a different page that is being searched. If that makes any sense. :)
Use the <form> tag's action attribute to submit the form to the search page like:
<form action="http://www.site.com/search">
I also just realized that you are probably only looking to search specific content types so you may wish to look into the Custom Search module (http://drupal.org/project/custom_search).

wicket wicket:link

I am trying out the following example. ChangeTextOnClick.html works fine as it is in the same dir as the file that contains the following snippet (WicketLink.html). But HelloWorld.html does not work as it is in another package. How do i refer to page on a different package.
<wicket:link>
<ul>
<li>
Change Text On Click
Back
</li>
</ul>
</wicket:link>
my pages are in the follow dir structure
com.merc.wicket.link.WicketLink.java and .html
com.merc.wicket.link.ChangeTextOnClick.java and .html
com.merc.wicket.main.HelloWorld.java and .html
In Wicket, you would normally reference another html file using a Link in Java to let Wicket generate the href for you. You can mount a Page under a fix URL (called Bookmarkable Link, as they are independent from the user session) or just use a Link.
For a Bookmarkable Link, you would do the following in the init() of your Wicket application class:
public class WicketApplication extends WebApplication{
protected void init() {
super.init();
mountBookmarkablePage("/ChangeTextOnClick", ChangeTextOnClick.class);
mountBookmarkablePage("/HelloWorld", HelloWorld.class);
}
}
With this, you can always reach those 2 Pages under the the URL given.
You can create a link pointing there using this in a MyPage.java:
add(new BookmarkablePageLink<ChangeTextOnClick>("myExampleLink"
,ChangeTextOnClick.class)
and in the corresponding MyPage.html:
<a href="thisGetsReplacedAtRuntime"
wicket:id="myExampleLink">Change Text On Click</a>
If you don 't want the Links to be bookmarkable, you don 't need the mountBookmarkablePage stuff in the init() and use a a Link instead of a BookmarkablePageLink.
Have a look at the Wicket wicki, you will find lots of helpful information there.
It turns out my guess was correct so here it is as an answer:
Wicket uses / as path separator, not ..
<wicket:link>
<ul>
<li>
Change Text On Click
Back
</li>
</ul>
</wicket:link>
is one solution, or using relative paths:
<wicket:link>
<ul>
<li>
Change Text On Click
Back
</li>
</ul>
</wicket:link>
The above answer is perfect.It need not only to be in the different folder in the project,but also it can be anywhere in the folder in the system.Still it possible to refer that file,if the configuation is done correctly in WicketApplication file.