Magnolia 6.0 get current node in endpoint - magnolia

i have here a magnolia 6.0 running which uses ftl and need to find out the requested node to build a navigation and mark the current node as active.
I iterate over the pages and the subitems to get each navigation entry. but i didn't get the current node.
Example:
my-website
page 1
sub page 1-1
sub page 1-2
page 2
sub page 2-1
sub page 2-2
the api calls to magnolia looks like the following:
my-website/page-1/sub-page-1-2.json
So i need to know sub-page-1-2 is the current in the ftl templates.
I found a similiar questions, but this does not work for me:
FreeMarker - Get Current URL
So i tried the following:
use cmsfn.parent(content, "mgnl:page") but with this i get the current page-module but not the current sub page.
also use cmsfn.decode(item) but this gets me just the url to the item
Is there a way to get the asked node in the ftl template?

Yes, there is a way to get the requested node (content) or more information regarding the context.
Please have a look at https://documentation.magnolia-cms.com/display/DOCS60/Rendering+context+objects
Hope that helps,
Cheers,

Related

Is always necessary show GET parameters in the URL?

I'm making a React application in which I make some API calls for a pagination of products. The url I'm using for showing every page in the products list is something like:
http://www.example.com/products
So my question is if it's necessary to have something like this for the page 1:
http://www.example.com/products?page=1
Something like this for the page 2 and so on..
http://www.example.com/products?page=2
It's not at all necessary. It's totally up to you how you design it.
But with having this kind of link it will be easy for the user to hop in to some particular page just through the link

Wordpress add new record custom admin.php not working

I have some custom wordpress migration, where there are a few custom plug-ins.
The problem which I am facing is that I have add new team member as link the folling link:
Add New
so when I press that button I am getting the form but no input fields are presented.
The question is more of where to be looking in order to resolve this, since it is using admin.php wordpress functionality? Any suggestion or guidance will help. Thanks.
A late answer but...
Some key guidance is given in Admin Screen Reference. See:
Top level pages admin.php?page={page_slug} toplevel_page_{page_slug}
Sub pages admin.php?page={page_slug} {parent_slug}_page_{page_slug}
So, you are working with either a (top) menu page or a sub menu page.
You need to search for calls to add_menu_page() and add_submenu_page() that pass wb_team_list as $menu_slug. The $function passed in the function call generates the page content.
(The answer was verified against the theme I am currently working with.)

Umbraco temporary page

I was building an Umbraco 7.4.3 site, and I was ended up to this situation.
I have a node structure inside Umbraco like this.
So, I have a Student and Teacher node under Home.
The Student node will show a detail about student.
Now I want to have a page where I can edit a Student, "I want a separate page (not popup) linking to a page where I can edit a student", something like a /edit-student/?id=2.
But in order do that I will end up in a structure like this, see screenshot
See? I have an extra node EditStudent just to have a page where I can edit student, I can call this page by /Student/EditStudent/?id=2
But I don't want to have this node "EditStudent", I feel it was making my node structure dirty.
I want a solution that I can still have a url like this /Student/EditStudent/?id=2 but I don't want to see a node "EditStudent" under Student or somewhere else inside my Umbraco.
Is this possible to happen? something like a virtual url (but not aspx) pages.
Found the answer I posted at our.umbraco.org forum.
Just create a template and Ill name it as "Edit", then you can access like this url: /Student/Edit/, and of course you can add parameters.
If there is no other node name "Edit" found under Student then it will use "Edit" template as alternative.

My portfolio project doesn't show on project page it shows in different page when I add project it asked to view project

I'm using construction theme.When I add a new project or category on my website it doesn't show on my website. Only I can see my project whenever I save my project and it give the option to view your post. but actually it is not. SNL->Projects->Project 4 it must look like this but when I add some project it doesn't show anywhere. Please help!!!
I have a website page called projects. When I post a project or portfolio on my website it doesn't show in project page or anywhere else. Like it's hidden not posted on front view. When I save portfolio Wordpress give tne option to view your post when I click on it, it shows that this project is coming from ABC category. It is showing like this look SNL Construction ->abc -> Project 2. It must look like this SNL construction->project->abc->project 2. That means the portfolio I'm posting is not going anywhere it's creating its own location. I want is when I post an portfolio it must go in PROJECT or OUR WORK page. Like products goes to their own category.

Is there a Drupal module that can redirect from root URL to a certain page?

I wonder if there's a Drupal module that can do this kind of functionality: if i go to home page, it will take me to some subpath within the site. i.e. www.something.com will redirect to www.something.com/product/node/11.
I tried creating an alias and used Path redirect module but for some reason, i can't reach the expanded URL when going to home page. it will display the content of www.something.com/product/node/11 but still using www.something.com.
I'm thinking that this can only be implemented in Apache server, not inside Drupal?
Note that our purpose of doing this feature is whenever a new product is created, we want our home website to point to that (i.e. www.something.com -> www.something.com/product2/home, before www.something.com/product1/home). If this is configurable inside Drupal, the changes would be easier and can be done by a Drupal administrator.
You should be able to go to /admin/settings/site-information and set the Default Front Page at the bottom of the form. That doesn't do a redirect: the home page will BE whatever you set the default to.
Create a new view (Node type) named "frontpage_redirect"
As suggested in answer by Michael D, create and save a view configured to search for your specified criteria:
display: page display, path = frontpage-redirect
pager: 1 item
row style = Fields
fields: Node => Node ID
filters: node type = product
sort: post date desc
Save your new view
At admin/config/system/site-information, set your "Default front page" to the view display path above (frontpage-redirect in my example)
In the view edit screen select "Theme: Information" link in the Page display. Look for the most specific (rightmost) entry under "Field Node: Nid (ID: nid)" - should be something like views-view-field--frontpage-redirect--page-1--nid.tpl.php, but will depend on the view name and display name. Copy the default views template views-view.tpl.php into your theme folder using the filename from 3.
Edit the template and put this code in it:
if (isset($row->nid)) {
drupal_goto('node/' . $row->nid);
}
This way of setting up the redirect lets you drive it from Views, which gives flexibility. When your customer decides in six weeks that they want to feature only the latest red product on the frontpage, you'll be able to update the logic behind the redirect using the views UI. (And you can do it from your phone on the train home!)
You avoid the need to create a custom module (which is easy enough, but does add some complexity) or to move your site logic into .htaccess.
Using the Views module, create a new view that displays one full node, ordered by last created, filtered appropriately, then create a page display in the view. Then follow Graham's instruction to set the site homepage to the view URL.
Another way would be to write a very simple custom module that db-queries for the latest node created of the sort you want, grab the URL to the page, then redirect there using drupal_goto().
There are other ways to do what you want inside Drupal, but I can't think of any that are more direct and simple at the moment...
What you are asking seems wrong. Sorry if I misunderstand some detail, but it seems you should reconsider the problem on a higher level.
If I understand you right, you want to show the page for the latest product as the homepage?
If so, maybe you should turn that into show the latest project page on the homepage. That fits a lot better with the RESTfullness of the web. And with expectations of the users.
The pattern would then be:
GET /products/22 shows product 22
GET /products/23 shows product 23
GET /product/latest shows the last product (in this case, the page would be exactly similar to /products/23)
To achieve that, you can use views module.
On similar lines to Michael D's post, assuming you want to pull the most recently published product from a custom content type called "products," you could put something like this in your settings.php:
function yourtheme_preprocess_page(&$variables) {
$query = db_query("SELECT nid FROM {content_type_products} ORDER BY nid DESC LIMIT 1");
while ($row = db_fetch_object($query)) {
$redirect_nid = $row->nid;
}
if ($variables['is_front'] == 1) drupal_goto("/node/" . $redirect_nid);
}
modify the .htaccess file.
http://drupal.org/node/50322#comment-2456576

Resources