New pages ignore ruby code - Rhomobile - erb

In my Rhomobile project I just created a new .erb file in /app . But the commands between <%= %> are just ignored... In example, I have a link like this:
'href="<%= url_for :controller => :Settings, :action => :do_sync %>"'
but when I click it, nothing happens. How do I create new page files in which I can include such commands? May I map it in some config file?
Thanks for the help.

I think your problem is the location of your .erb file and not your use of url_for.
Assuming that you refer to an action in your Settings controller, the .erb file should be located in /app/Settings. This means that if you want to render an action called login from your Settings controller, you would have to create the file login.erb so it is located at /app/Settings/login.erb.
In your rhoconfig.txt you can define the application start and settings path, if you want to change it so you start your application in a specific controller instead of in /app/index.erb.

Related

__layout.reset has been removed in favour of named layouts

I have a page set up in this format
original reset image›
I looked at forums and it said i should change the inner layout page to __layout#reset.svelte. However when i do that, I get another error.
reset image using #reset instead of .reset
Does anyone know how i can put in a reset __layout inside of a folder and get it to override the parent layout?
Your error is because __layout#reset.svelte would be looking for a __layout-reset.svelte file in it's current directory, or any parent directory directory, to be a sub-layout for. You don't have a __layout-reset.svelte file.
As Thomas Hennes mentioned in the other thread. If you wanted to have it act like the reset, you'd need to create a __layout-reset.svelte file in the current folder or (more useful for the entire app, in the root folder) and have it be a blank <slot />. From there, you can do __layout#reset.svelte to which will allow you to make a completely new layout.
I think that you can solve this problem by fallowing this steps :
Create "__layout-choseNameYouWant.svelte" at the same level as "__layout.svelte"
Create "guides#theSameNameYouGaveForLayoutFile.svelte" at the same level as
about.svelte
Layouts can themselves choose to inherit from named layouts
create "__layout-root.svelte" at the same level as index.svelte and about.svelte with the following code
<slot/>
create "__layout#root.svelte" in guides folder with the following
<slot></slot>

Creating a custom url for an static html page

I need to create a page like http://www.example.com/strong and the file to support that are inside my docroot/strong/index.html.
Inside my docroot there are other folders with their index file as well. For example
docroot/site1/index.html
docroot/site2/index.html
docroot/strong/index.html
So when user types in http://www.example.com/strong it should open docroot/strong/index.html without changing the URL. Can I achieve this?

how to point root folder of DAM Display portlet programatically

How to set one of the folders as root folder of Documents And Media Display portlet by programmatically.PFA image
Liferay Major Version
Your question is tagged as Liferay 6 and Liferay 7. The two releases are drastically different. This answer assumes you are using Liferay 6.x since you are asking about the DDM portlet as opposed to the OSGI module.
Programmatically setting that input resource to default as a folder of your choice requires you to create a JavaServer Page hook for a JSP in the Document Library Display portlet. I am going to briefly explain how to create the JSP hook before getting into particulars.
Create a Hook
From Liferay's Knowledge base
From your command line terminal, navigate to your Plugins SDK’s hooks folder. To create a hook project, you must execute the create script. Here’s the format to follow in executing the script:
create.[sh|bat] [project-name] "[Hook Display Name]"
On Linux and Mac OS X, you’d enter a command similar to the one in this example:
./create.sh doc-lib-disp-hook "Document Library Display Hook"
On Windows, you’d enter a command similar to the one in this example:
create.bat doc-lib-disp-hook "Document Library Display Hook"
Liferay IDE’s New Project wizard and the create scripts generate hook projects in your Plugin SDK’s hooks folder. The Plugins SDK automatically appends “-hook” to your project name.
You will need to have Apache ANT installed for this to work. Please reference the following documentation if you need to install it.
https://www.mkyong.com/ant/how-to-install-apache-ant-on-windows/
Once the hook is created open it in your Liferay IDE or Liferay Developers Studio (or Eclipse).
In your IDE click the down arrow right below File (top left corner)
Choose Liferay Plugin Project from Existing Source
Double click on the doc-lib-disp-hook folder in your Plugin's SDK Hook directory to open.
You should see something similar to this (with different name).
Override JSP
Now that you have successfully created a hook plugin, we need to override the necessary file. There are two files in particular that we need for this hook
html/portlet/document_library_display/configuration.jsp
html/portlet/document_library/init.jsp
We need both files to logically walk through this example although we only need to actually override one of them.
To override the JSP's execute the following steps
Under your META-INF folder create a new directory called custom_jsp
Open up liferay-hook.xml in Overview mode
Click the Green Plus sign (to the right of Custom JSP label)
Search for both files listed above (copy and paste the URL into the window) then click save.
You will now notice you have the following directory structure.
Let's first open the configuration.jsp. This is the code that produces the GUI you took a screen shot of. Find the following code block.
<aui:field-wrapper label="root-folder">
<div class="input-append">
<liferay-ui:input-resource id="rootFolderName" url="<%= rootFolderName %>" />
<aui:button name="openFolderSelectorButton" value="select" />
<%
String taglibRemoveFolder = "Liferay.Util.removeFolderSelection('rootFolderId', 'rootFolderName', '" + renderResponse.getNamespace() + "');";
%>
<aui:button disabled="<%= rootFolderId <= 0 %>" name="removeFolderButton" onClick="<%= taglibRemoveFolder %>" value="remove" />
</div>
</aui:field-wrapper>
Inside that block you will see the Root Folder element you wish to set.
<liferay-ui:input-resource id="rootFolderName" url="<%= rootFolderName %>" />
As you can see the folder's url is already set by default to the variable rootFolderName. We need to find where that variable is first initialized.
We need not modify this file at all. I had you include it and open it so you can follow through logically.
If you notice rootFolderName is not initialized anywhere in the configuration.jsp file. Therefore we need to investigate the init.jsp file because it is an include at the top of the page. If you open that file you will notice the following block.
String portletResource = ParamUtil.getString(request, "portletResource");
if (layout.isTypeControlPanel()) {
portletPreferences = PortletPreferencesLocalServiceUtil.getPreferences(themeDisplay.getCompanyId(), scopeGroupId, PortletKeys.PREFS_OWNER_TYPE_GROUP, 0, PortletKeys.DOCUMENT_LIBRARY, null);
}
long rootFolderId = PrefsParamUtil.getLong(portletPreferences, request, "rootFolderId", DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
String rootFolderName = StringPool.BLANK;
if (rootFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
try {
Folder rootFolder = DLAppLocalServiceUtil.getFolder(rootFolderId);
rootFolderName = rootFolder.getName();
}
catch (NoSuchFolderException nsfe) {
}
}
This code is basically saying we are going to initialize rootFolderName blank. However if rootFolderId is set higher than 0 either by
Portlet preferences, or
Request Parameters
then we will set rootFolderName accordingly.
Conclusion
If you want to set rootFolderName to a folder of your choice programmatically by default you can a few things. The easiest thing to do would be to get the folder's id and modify the code like this
long folderIdConstant = 999999L; // place folder id here
long rootFolderId = PrefsParamUtil.getLong(portletPreferences, request, "rootFolderId", folderIdConstant );
That would set the default root folder programmatically. Just build and deploy now.

Liferay 6.1.20 : Minimize and bundle theme Javascript

Is there a way to apply Liferay's built-in javascript minimizing and bundling capability to the javascript I've included in my theme? I have javascript.fast.load=true in portal-ext.properties and Liferay's javascript is getting bundled & minified in everything.jsp as expected. Also, all portlet javascript that is included via a portlet's liferay-portal.xml file is getting minified as expected. However, I've got many javascript files that are included in my theme because they are utilized on every page and I would like them to get minimized and bundled into everything.jsp along with all the Liferay portal javascript. I've tried the approach suggested by this question, but I think this will only work with a hook because the MinifyFilter will look for files to minify & bundle within the context of the portal web app, i.e. <TOMCAT>/webapps/ROOT. Is there a way I can specify a path to files in a different web app (the theme in this case) as the javascript.bundle.dir parameter? In other words, something like javascript.bundle.dir[javascript.jquery.files]=/<theme-path>/js. I've tried many variations and combinations of javascript.bundle.ids, javascript.bundle.dependencies, etc. to no avail. I know I can get around the problem by putting the javascript in a hook or putting it in portlet and embedding it in the theme but I'd really like to just keep the javascript in the theme. Is there a reasonable way to accomplish this?
There doesn't seem to be a good way to include javascript files from the theme with the minified and bundled Liferay javascript. While you can define a javascript bundle in portal-ext.properties that includes your files, you can't order the dependencies the way you need to in order to get everything to work using only configuration. You can configure the "everything" bundle to depend on your custom bundle but that's not very useful. It would be far more useful if you could configure Liferay to use your custom bundle as the new "everything" bundle and tell Liferay that your bundle depends on Liferay's "everything" bundle. However, the actual bundle ids that are included are hard-coded in Liferay's top_js.jspf file. So the only way to get everything to work would be to override Liferay's definition of javascript.everything.files to include both Liferay's files and your custom javascript. This doesn't seem like a very good solution since it tampers with Liferay's list of included javascript which would certainly be a pain when you need to upgrade Liferay. As Olaf suggested, you can minify and bundle the js yourself and just include it in the portal_normal template. That is a very reasonable solution and what I would normally recommend. Unfortunately I was in a situation where my customer was requesting that all the files be bundled in one file and we are not allowed to modify the build process.
Hook Workaround
There is a workaround using a hook that I don't necessarily recommend but it does accomplish the goal of getting all javascript minimized and bundled along with Liferay's javascript. The basic process is to move the javascript from the theme into a hook, configure a new bundle in portal-ext.properties that includes all of your files, then create a jsp hook for top_js.jspf that includes your new bundle instead of the hard-coded javascript.everything.files or javascript.barebones.files bundles. The steps are:
Move your javascript files into a hook project and place them under html/js. This will cause
the files to be copied to the javascript directory under the portal
web app, i.e. <TOMCAT_HOME>/ROOT/html/js. This is where the Liferay
MinifyFilter looks for javascript files to minify & bundle.
Define a javascript bundle in portal-ext.properties that references
all of your javascript files that need to be included in the bundle
created by the MinifyFilter. Your portal-ext.properties file should
look something like this:
minifier.enabled=true
javascript.fast.load=true
javascript.my.js.files =\
jquery.1.11.1,\
my-js-lib.js,\
my-other-js-lib.js
javascript.bundle.ids=\
javascript.barebone.files,\
javascript.everything.files,\
javascript.my.js.files
javascript.bundle.dir[javascript.my.js.files]=/html/js
# our bundle depends on all the files in the "everything" bundle
javascript.bundle.dependencies[javascript.my.js.files]=javascript.everything.files
Create a JSP hook for top_js.jspf. This file is under
<TOMCAT_HOME>/ROOT/html/common/themes. It is the file that includes
either the barebones.jsp or everything.jsp based on whether the user
is authenticated (if the user is authenticated they get
everything.jsp otherwise barebones.jsp is included). Replace the
references to the javascript.everything.files and/or
javascript.barebones.files bundles with a reference to your new
bundle based on your requirements. For example, if you only want to
include your javascript when the user is authenticated you just have
to replace references to javascript.everything.files.
Specifically, you make the following changes:
This line:
<script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNDynamicResourcesHost() + themeDisplay.getPathJavaScript() + "/everything.jsp", "minifierBundleId=javascript.everything.files", javaScriptLastModified)) %>" type="text/javascript"></script>
is changed to this:
<script src="<%= HtmlUtil.escape(PortalUtil.getStaticResourceURL(request, themeDisplay.getCDNDynamicResourcesHost() + themeDisplay.getPathJavaScript() + "/everything.jsp", "minifierBundleId=javascript.my.js.files", javaScriptLastModified)) %>" type="text/javascript"></script>
and this line:
javaScriptFiles = JavaScriptBundleUtil.getFileNames(PropsKeys.JAVASCRIPT_EVERYTHING_FILES);
is changed to this:
javaScriptFiles = JavaScriptBundleUtil.getFileNames("javascript.my.js.files");
* Non-Global Hook Caveat *
If you are putting the javascript and top_js.jspf hooks in a project with other hooks and the project is configured to use non-global jsp hooks, i.e. <custom-jsp-global>false</custom-jsp-global> the solution becomes more complicated. This is because setting <custom-jsp-global>true</custom-jsp-global> makes Liferay rename your hook jsp files rather than renaming the portal's jsp files. For example, if custom-jsp-global is set to true, which is the default setting, then when I make a hook for a page called top_js.jspf, the portal will rename the original top_js.jspf file to top_js.portal.jsp and my hook file will be used instead of the original. However, when custom-jsp-global is set to false then the original file stays intact and the jsp hook file is renamed to something that includes the name of the hook like top_js.my-hook.jspf. This is a problem when you're creating a hook for included files such as top_js.jspf because the file that includes top_js.jspf will still reference the old file, not the hook which is named top_js.my-hook.jspf. This means you have to also create a hook for the file that includes your hook. Likewise, if that file is included by another file you have to make hook for that file and so on until you reach the top level page. So, in the example of trying to create a hook for top_js.jspf we have to also do the following:
Create a hook for top_head.jspf and replace the reference to top_js.jspf with a reference to our hook, top_js.my-hook.jspf.
So this line
<%# include file="/html/common/themes/top_js.jspf" %>
becomes this
<%# include file="/html/common/themes/top_js.my-hook.jspf" %>
The top_head.jspf file is actually included by the theme in
portal_normal.vm using a Velocity variable that is initialized in
init.vm on the following line:
You need to assign $top_head_include to the top_head.my-hook.jspf hook in the theme's init_custom.vm, like this:
#set ($top_head_include = "$dir_include/common/themes/top_head.my-hook.jsp")
Your Theme has access to all of the HTML the portal generates. While you might need one extra file to be loaded (css gets minified for the whole theme anyway), you can easily add all of the (already) minified js files to your theme and include them in your templates/portal-normal.ftl implementation.
It would be as easy as having this section in portal-normal.ftl:
<head>
<title>${the_title} - ${company_name}</title>
<meta content="initial-scale=1.0, width=device-width" name="viewport" />
${theme.include(top_head_include)}
<script src="${javascript_folder}/my-minified-javascript.js"/>
</head>
Note: All but the <script> line is already in the default ftl file. This way you'll end up with two js files being loaded (the barebones or everything, plus your own), but that's not too bad. You can also add the minification to your theme's build process, so that you don't have to maintain the minified code manually.
Another alternative, which I haven't tried, is examining the use of Liferay's javascript minifier (e.g. in webapps/ROOT/html/common/themes/tom_js.jsp) to see how to utilize it to dynamically minify your files.
For completeness reason (maybe it helps someone else) I'm leaving my first answer here, which you couldn't use as you say in the first comment:
There's a section in portal.properties, to be overloaded in portal-ext.properties with this heading:
##
## JavaScript
##
#
# Set a list of JavaScript files that will be loaded automatically in
# /html/common/themes/top_js.jsp.
#
# There are two lists of files specified in the properties
# "javascript.barebone.files" and "javascript.everything.files".
#
# As the name suggests, the barebone list is the minimum list of JavaScript
# files required for most cases. The everything list includes everything
# else not listed in the barebone list.
#
# The two lists of files exist for performance reasons because
# unauthenticated users usually do not utilize all the JavaScript that is
# available. See the property "javascript.barebone.enabled" for more
# information on the logic of when the barebone list is used and when the
# everything list is used and how to customize that logic.
#
# The list of files are also merged and packed for further performance
# improvements. See the property "javascript.fast.load" for more details.
#
e.g. configure javascript.everything.files (the default is below that comment, for brevity I'm not copying that here)

Path to layout xml files in magento

I have seen that we can place our layout xml files in
app/design/frontend/default/default/layout
or we can place our customization inside
app/design/frontend/base/default/layout/local.xml
file, but I have read at magebase and at magentocommerce that we can place our layout files under
app/design/frontend/your_interface/your_theme/layout/
or
app/design/frontend/[package]/[theme]/layout
So if we I have package like 'Kaushikamdotcom' in 'app/code/local', should I have to create that same package under 'app/design/frontend/' ? I tried many patterns, but nothing worked out for me.
I am quite sorry that I have made such a blunder asking this question, but I am answering this as lots of people will be making the same mistake. Package means; in the admin side of magento open
System->Configuration->Design
Then change the configuration scope to Main website. Then select Package section, uncheck the default check box and use your package name such as "Test". Then create the following folder structure.
app/design/frontend/Test/default/layout
Place your layout xml files here. If you are using your own themes use that name instead of default.
It depends what layout-xml file you have.
If you want to build up your theme, use the local.xml file in your theme dir.
If you write an extension and want to add a block to use inside this new extension, add a layout-xml file via config.xml and add it under base/default/layout/yourname.xml
When you do it this way, your theme-related changes only appear in the theme and your extension-related changes are theme-independent

Resources