Jump to content

Help? Works with fields


drilonb
 Share

Recommended Posts

Hello i am a new with this CMS i like to know if its possible to call fields like:

I create one template Slides.php and add fields Image and text , i like to call fields of this template to other template name like in home.php slider work in slider page but not in other pages ,

example of your template

			<?php

		// Grab a random image from the homepage and display it.
		// Note that $homepage was loaded above where we generated the top navigation.

		if(count($homepage->images)) {
			$image = $homepage->images->getRandom(); 
			$thumb = $image->size(232, 176); 	
			echo "<a href='{$image->url}'><img id='photo' src='{$thumb->url}' alt='{$thumb->description}' width='{$thumb->width}' height='{$thumb->height}' /></a>";
		}

		?>

how to creat like this to call other pages not from homepage .

i try this but works only in sliderat template

<?php 
                if(count($page->sliderat->slider1)) {
			$image = $page->sliderat->slider1->getRandom(); 
			$thumb = $image->size(400, 200); 	
			echo "<img id='photo' src='{$thumb->url}' alt='{$thumb->description}' width='{$thumb->width}' height='{$thumb->height}' /></a>";
		}
                 ?>

Ame sorry for my language.

Link to comment
Share on other sites

I'm confused by the field/page names -- is the name of the field "sliderat" or "slider1"? :) But lets assume there is a field named "images" on the page "/mypage/" and you wanted to pull a random image, like in your example:  You'd do it like this:

<?php

$mypage = $pages->get("/mypage/"); 
if(count($mypage->images)) {
    $image = $mypage->images->getRandom();
    $thumb = $image->size(400, 200); // if you need a thumbnail
    // then output the thumbnail and/or image like in previous examples
}

Also, you had mentioned templates in a context that I'm not sure I understood. Templates define a type. You don't pull data from a template, but from pages that use that template. So think of templates like the database schema for a table, and pages like the rows of data in that table.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...