Template on Web content structure - liferay

I've made a web content structure which contain a field "Query_Title". The field Query contains sub fields : "Description" and "url".
I had to create a template for this new structure which is :
#if (!$Query_Title.getSiblings().isEmpty())
#foreach ($cur_Query_Title in $Query_Title.getSiblings())
$cur_Query_Title.getData()
#end
#end
I would like to display every field : Title (as i already do) and Description and url as well, but i have no idea how to access them...
Any idea?

$cur_Query_Title is of type TemplateNode, which is (beside some other functionality) a map that contains the sub fields:
$cur_Query_Title.Description.data and $cur_Query_Title.url.data should work for your example.

Related

How can set in page title with the document name in Kentico?

I need set the page title dynamically because in my node actually exist 1000 documents, so I think that exist a way to do it automatly.
I'm using Kentico 10
Use a macro. In the parent page of all your documents, you can use a field from the specific page type or use the document name.
For example if you have a page tree like this:
-Products
--Product 1
--Product 2
In the -Product pages metadata add
Page title: {%DocumentName%}
or
Page title: {%PageTypeField%}
Using the macro will allow you to dynamically get those values vs. having to code each one manually.
I'm not sure that I understand your question, but if you want:
To set page title for your documents, to be shown in browser, you should follow link in documentation.
To iterate over all nodes and update document name/ page title with some custom text, you should look into Kentico API docs. You should look into section for Updating published pages (see code example bellow):
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
var pages = tree.SelectNodes()
.Path("/Articles/", PathTypeEnum.Children)
.WhereLike("DocumentName", "Coffee%")
.OnSite("DancingGoat")
.Culture("en-us");
foreach (TreeNode page in pages)
{
page.DocumentName = "Updated article name";
page.SetValue("ArticleTitle", "Updated article title");
page.Update();
}

How do I get a relative URL to a media item from my codebehind?

I have a layout web part which has a "Teaser" field. The "Teaser" field uses a "media selection" form control. In this case the field is set to an image uploaded to one of the sites media libraries.
I want to render that image, so I'm trying to get the relative URL to it in the codebehind:
if (Teaser != Guid.Empty) // Teaser is {8d7fa1ab-b304-474f-9ab9-2e17e8fee84f}
{
var mediaInfo = MediaFileInfoProvider.GetMediaFileInfo(Teaser, SiteContext.CurrentSiteName);
// mediaInfo is null so the next line crashes
var libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(mediaInfo.FileLibraryID);
string url = MediaFileURLProvider.GetMediaFileUrl(mediaInfo, SiteContext.CurrentSiteName, libraryInfo.LibraryFolder);
The "mediaInfo" variabe is null, so the code crashes.
How can I get a relative URL to my media file?
You cannot add the "Media selection" form control in combination with an field type Guid. Then you need to create an custom form control if you need to have only the Guid.
But an better solution is add an field with the data type "text" and in combination with the form control "media selection" then adds directly the relative URL inside the field when selecting an image from the media library.
If you also need the MediaInfo then you can get this object with the parameter "mediaFilePath", like described here : https://devnet.kentico.com/docs/8_2/api/html/M_CMS_MediaLibrary_MediaFileInfoProvider_GetMediaFileInfo_3.htm
Good luck and if you have more questions you can always ask them here on StackOverflow or on http://devnet.kentico.com/questions-answers.
If this answer helped you, please vote for my answer :-)

Wordpress: Display content from a Custom Post Type within a regular Post

I feel like there is a really simple solution to this problem. However, after trying to solve it for about 3 hours unsuccessfully, I humbly come to you.
The Basics:
A custom post type, " band ", has been created, and has several
custom fields (which were created through the Advanced Custom
Fields
plugin.)
The Question:
How would I get and display the contents (specifically custom field data) of a specific band entry (using its ID or title or slug) inside of a regular post? (see diagram below)
(source: thisnewband.com)
.
Methods to Trigger the Display of the Custom Post Type:
We have to provide the ID/title/slug so that it knows what band post's content to display
Shortcode (such as [band id="21"] ) (added inside post content)
Custom Field (custom field name band-id where you can input the ID of the band)
What I've Tried and Why It Didn't Work:
Shortcode
`[band id="21"] inserted in post editor field
Used WP_Query to query post with type=band and ID="21".
Code located in functions.php
Result: It would echo static text but would not display any post-specific content (Band Name, etc.). Also would not pull post-specific custom field data.
(also tried query_post with no luck)
Custom Field
Entered ID (21) into custom field on post editor page.
Coded it directly into the post template:
Used WP_Query and had the ID in the array pull from the custom field.
Result: Nothing good happened.
Where I Keep Running Into Trouble:
It's hard to pull the custom field data from the custom post type while inside an actual post
The Optimal Solution:
Whether it's by using a shortcode, custom field, or even a new widget, it would be easiest if one could:
Create a PHP template with the code for just how the single Band content is supposed to display. (Including the loop). Example name: band-block.php
Use get_template_part('band-block'); to echo this code (either in Post Template or Shortcode via functions.php)
Thanks for your help! Let me know if you'd like to see any of my code.
I knew you have found a solution for your problem, but for others i will give them an other solution:
You can query by ID, no problem. Look at these: http://www.advancedcustomfields.com/resources/field-types/relationship/
But you have to check in the custom field "return format" the box "Post IDs". Then it works perfectly well.
Sorry for my bad english ;)
Cheers
With some amazing help from Hobo, I was able to come up with a solution!
The main problem was with trying to query by 'ID'. No matter what we tried, it just never worked well. (It could be the way that the Advanced Custom Fields stored the ID field contents.)
What did work:
Created a custom field for the post page in which to put the Band (custom post type) post name/slug into. (Custom field was named post-band-name and created with the Advanced Custom Fields plugin.)
Placed the query code in the Post Template. (See code below)
Done.
The Solution Code
Add this loop after the normal loop...
<?php /* Display all the author's posts from the custom post type ('band') */ ?>
<?php
$authorid = get_the_author_meta( ID, $userID );
$args4=array('author'=>$authorid,'post_type'=>'band', 'numberposts'=> -1);
$cquery4=new WP_Query($args4);
if($cquery4->have_posts()):
while($cquery4->have_posts()):
$cquery4->the_post();
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<p><?php the_title();?></p>
</a>
<?
endwhile;
wp_reset_postdata();
endif;
?>

Building a list of downloadable items in Orchard 1.6

I'm fairly new to Orchard and I'm wondering about the "best" way of building a basic list of documents with a download link?
Say the scenario is this, I want to make a list of newsletters, the news letter are in PDF format and the users should be able to download then straight from the list view.
An admin, should easily be able to add a new newsletter and it should turn up in the list.
My current train of thought is to, all through the dashboard,
create a content type "Newsletter" with a title field and a Media picker field, using the media picker field to upload the PDF file.
Then create a query, with the filter on Content type "Newsletter"
Create a projection pointing to the query
However, this only gives me a list of content items, showing their title as links back to the actual content item.
I've tried adding a layout to the query and set it to display properties instead of content. By doing that I can get a list where I can control the "output" a bit more. And I've gotten it to list the title and by doing a Rewrite and putting in the MediaPicker.Url, it also displays the URL in the list. This is all good but here I get stuck..
As the MediaPicker.URL outputs the url in the format like ~/media/default/xyz/filename.pdf, I cant just put it into a a href, it doesn't give a correct download link to the file.
Soo, question is, am I thinking and doing this totally the wrong way or am I missing something obvious? All ideas and suggestions and more then welcome.
Use or adapt the following template override in your theme:
#{
var url = Model.ContentField.Url;
}
#if(Model.ContentField.Url != null) {
if (url.StartsWith("~/")) {
url = Href(url);
}
<div class="media-picker-field attachment-pdf">
<span>download</span>
</div>
}
Modify the text as needed. This template was a Fields.MediaPicker-PDF.cshtml that was used for a media picker field named PDF.

How Do I Style An Email Field in Drupal?

I have a list of Staff Members in Drupal6.
I need to style a node such that the email field of a staff member displays as "Contact [First word of Full Name field]". Clicking it causes a mailto:// link to open. BTW, I know that's not a recommended procedure because a contact form or a captcha would be more effective, but my client desires it.
Yes, I'm using the CCK module and the CCK Email module too.
So, again, I have a list of staff members using a custom content type. I have an email field in there using CCK Email module. When I display the node of a staff member, it's just showing the email address. My client wants to make it say "Contact Jonathan" if the staff member is named "Jonathan McDaniels", and so on with each node of each staff member. When "Contact Jonathan" or "Contact Sara" is clicked, it should do the ordinary mailto:// hyperlink stuff.
Yet another way to do this is with PHP. You can create a file node.tpl.php in your theme folder, copying this over from the garland theme. At the top of it, however, add this call:
require_once('node_hooks.php');
Now create a file node_hooks.php in your themes folder. This gives you enormous power now over a given node. You should start to learn the $node variable by doing this in your node_hooks.php file:
<?php
print_r($node);
Refresh your node page and then do a View Source in your browser on it. This will show you the object and each array element inside $node.
In my case I had a node of type 'staff' because that's what I called it when creating it. I also had a special CCK field called CCK Email and used it to create a field named field_staff_email. This was storing a value like jonathan#test.com. So, because of this, I could add this into my node_hooks.php file to do the search and replace on the content so that I get "Contact Jonathan" instead of the email address:
<?php
if ($node->type == 'staff') {
adjustStaffContactField($node, $content);
}
function adjustStaffContactField(&$node,&$content) {
$asWords = explode(' ',$node->title);
$sContact = htmlentities(strip_tags($asWords[0]));
$sContact = trim($sContact);
$sContact = "Contact $sContact";
$sLink = $node->field_staff_email[0]['email'];
$sContact = "<a href='mailto:$sLink'>$sContact</a>";
$sLookingFor = "$sLink";
$content = str_replace($sLookingFor, $sContact, $content);
}
To resolve this problem purely inside of Drupal without your own PHP code, you will need these modules in Drupal 6:
CCK Module
CCK Link Module
CCK Token Module
Unfortunately the CCK Email Module won't solve this problem.
Once copied into sites/all/modules and activated, you can then take your custom content type for Staff Member and create a field Staff Email as a type of "Link". Then, set the Title of that link to Static Title and set the text to:
Contact [title]
In the Default Value, set Staff Email URL to:
mailto:test#test.com
And set the Help Text to explain the default format requirement. Note if they enter this wrong without the mailto:, then the link will end up being passed off as a node, which is incorrect. Perhaps someone can think of a hook to test for this on this field in the PHP (or Javascript on form load) and swap it on the fly if forgotten.
Now, for only using the first name instead of the full name, you have a couple choices. You can use field_staff_firstname and field_staff_lastname (custom text fields you create) and not use the node's title (aka [title] token). Another route is to hook the page in PHP or with Javascript on form load, looking for this node element, intercepting it, and showing only Contact + first name.
I had the same problem of trying to turn a cck field into a mailto link. I found this posting but have found another, and fairly simple way, of doing it. It is done by overriding the cck theme template: content-field.tpl.php. This is the template which outputs the field values, so you can edit this to update the value you want. Copy the template into your own theme folder (don't overwrite the original), I then replaced the line:
<?php print $item['view'] ?>
(This was line 42 in my template), with:
<?php
// new lines for email field to turn it into a mailto link
?>
<?php if ($field_name=='field_email') : ?>
<?php // print_r($item);?>
<?php print "<a href='mailto:" . $item['value'] . "'>". $item['value'] ."</a>"; ?>
<?php else : ?>
<?php
// original line
?>
<?php print $item['view'] ?>
<?php endif; ?>
<?php
// end edit
?>
In this example, my field was called "field_email"
Hope this helps.
Ben

Resources