Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SILVERSTRIPE BOOK XML SITE TREE ISSUE


Go to End


40 Posts   6704 Views

Avatar
bummzack

Community Member, 904 Posts

26 August 2010 at 1:12am

I would definitely use SWFObject to embed flash content. A simple embed script for your purpose would look like this:

swfobject.embedSWF(
	"assets/swf/$FlashName", 
	"Navigation", 
	"$FlashWidth", "$FlashHeight", 
	"10.0", 
	"path/to/expressInstall.swf", 
	{
		"myFlashVar" : "$ImageName"
	}
);

As you can see, you can pass the FlashVars in JSON notation to the embed script. With SWFObject you usually also replace an existing DOM-Node with the flash. In above example, it would be the Element with the id "Navigation". So you could output your navigation in normal HTML and SWFObject replaces it with the flash content on browsers where flash is enabled.

IMHO this is the way to embed flash ;)

Avatar
servalman

Community Member, 211 Posts

26 August 2010 at 2:13am

Thank you !

I'm going to try that tomorow when I will deal with nav.

I tried something with SWFO on another project but it was this way :

the script was in inside the head

<head>
<script type="text/javascript" src="mysite/javascript/lib/swfobject.js"></script>
 <script type="text/javascript">
  swfobject.embedSWF("assets/swfs/tickerdef.swf", "myContent", "1122", "50", "9.0.0");
swfobject.embedSWF("assets/swfs/sample.swf", "mySample", "10", "10", "9.0.0");
  </script>
	</head>

and inside the template as an include I had this

   <div id="myContent">
      <p>Alternative content</p>
    </div>
<div id="mySample">
      <p>Alternative content2</p>
    </div>

Can use this form and still pass my FlashVar ?

also my problem is to retrive dynamically the path to my export page.
I suposed I have to create a function in my Page.php controller and i can't directly write :
"myFlashVar" : "$Link/export " (I supose $Link gives you the current link of the page)

Also I have 3 questions mind before starting
- can I put the script inside a div to deal with it's position with css ?
- can it be use as an include so I keep my templates readable
- paramters like "wmode" are passed the same way, there seems to be a special order ?


<div id="flashmovie">
<script type="text/javascript">
swfobject.embedSWF(
"assets/swf/$FlashName",
"Navigation",
"$FlashWidth", "$FlashHeight",
"10.0",
"path/to/expressInstall.swf",
{
"myFlashVar" : "$ImageName"
}
);
</script>
<div id="flashmovie">

Thanks again for all you help and time I really apreciate it

Avatar
bummzack

Community Member, 904 Posts

26 August 2010 at 3:53am

What you did is exactly what I'm proposing.. you just left out the FlashVars and wrote it all on one line :)

The SWFObject parameters are best explained here: http://code.google.com/p/swfobject/wiki/documentation#How_do_you_use_Objects_to_define_your_flashvars,_params_and_obje

I'm pretty sure you can simply write: "myFlashVar" : "$Link/export", or maybe rather "myFlashVar" : "{$Link}export", since $Link adds a trailing slash AFAIK.

Regarding your questions:
- can I put the script inside a div to deal with it's position with css ?
Why would you want to do that? Styling a script is pointless. You should style the container that the flash will be inserted into (the one you pass as ID to the swfobject script)

- can it be use as an include so I keep my templates readable
Sure

- paramters like "wmode" are passed the same way, there seems to be a special order ?
Read the SWFObject documentation (see link above)

Avatar
servalman

Community Member, 211 Posts

27 August 2010 at 1:43am

Hi Banal

I just started to dive in my flash xml big bath and I start with an error :

by the way it seems that simply setting control Menu(2) gives me the subcategory I needed but It doesn't give me the parent node for obvious reason.
What I'm looking for in my xml is to retrieve the parent node (product categories and it's children

here is my codes:

Page_export.ss

<?xml version="1.0" encoding="UTF-8"?>
<% control Menu(2) %>
$ExportContent
<% end_control %>

here is my ExportPage

<node id="$ID" label="$Title" link="$Link" classname="$ClassName">
   <% control Children %>
   $ExportContent
   <% end_control %>
</node>

the error I get is the follwing :

Erreur d'analyse XML : données incompréhensibles après l'élément de document

Emplacement : http://evidens2.net/evidev/sahos-by-evidens/saho-purifiant/export

Numéro de ligne 7, Colonne 1 :<node id="37" label="Saho Nourrissant" link="/evidev/sahos-by-evidens/saho-nourrissant/" classname="EditorialPage3">
^
If you don't read french it says that it is not xml.

Any Idea ?

Thanks again

Avatar
bummzack

Community Member, 904 Posts

27 August 2010 at 3:20am

A well-formed XML Document only has one root node.
So you should wrap that code in a XML node:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<% control Menu(2) %>
$ExportContent
<% end_control %>
</root>

I don't know why you would need the parent node.. don't you have that in some other XML document? You have to get to that second level somehow, don't you? Also: If you get a second level, then why not simply add the current page to the XML.. that should output the current parent?

So instead of the <root> node, just output the current (parent) node?

<?xml version="1.0" encoding="UTF-8"?>
<node id="$ID" label="$Title" link="$Link" classname="$ClassName"> 
<% control Menu(2) %>
$ExportContent
<% end_control %>
</node>

Avatar
servalman

Community Member, 211 Posts

27 August 2010 at 3:33am

Edited: 27/08/2010 3:34am

Hello and thank you againI get

It's funny how I get lost :)

The XML out put is ok now .

I need the parent node because I need it's title like you can see in picture :

The menu I want to output as an xml form (I'm trying my fractioned appoach) is that "PRODUCTSMENU" on the left side on the top of it you can see that the title is the name of 'ProductSection1' wich is the parent node.

I tried your snipset but it gives me twice the first childNode, in my case (still menu on the left) I get 2 "Serum" node and then the rest

What do you thik ?

here is the link
http://evidens2.net/evidev/sahos-by-evidens/saho-purifiant/export

Thank you

T

Attached Files
Avatar
servalman

Community Member, 211 Posts

27 August 2010 at 4:36am

Edited: 27/08/2010 5:53am

Hello Banal

I just edited my last post because I realised that it was very messy

I make it clearer :

I want to adapt your xml technique to a different template :

so I have :

Product.php

<?
class Product extends DataObject
{
	static $db = array (
		'Productname' => 'Text',
		'Presentation' => 'Text',
		'Contenance' => 'Text',
		'Price' => 'Text'
	);
 
	static $has_one = array (
		'ProductPage' => 'ProductPage'
	);
 
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Productname'),
			new TextField('Presentation'),
			new TextField('Contenance'),
			new TextField('Price')
			//new TextareaField('Quote')
			

		);
	}

	public function Link() {
return $this->ProductPage()->Link("show/$this->ID");
}

  public function FlashVarName() {
return "FlashVarName=$this->Productname";
 }

}

then I have ProductPage.php

<?
class ProductPage extends Page
{
	static $has_many = array (
		'Products' => 'Product'
	);

     static $db = array(
   
'ActifsProduct' => 'HTMLText',
'OtherProducts' => 'HTMLText',
'TextProduct' => 'HTMLText',
'GestesProduct' => 'HTMLText',
'SecretProduct' => 'HTMLText',
      'ImageName' => 'Text',
	  'FlashName' => 'Text',
	  'FlashHeight' => 'Int',
	  'FlashWidth' => 'Int',
	  'LayoutType' => 'Text'
   
);
 
	public function getCMSFields()
	{
		$f = parent::getCMSFields();
		$f->addFieldToTab("Root.Content.Products", new DataObjectManager(
			$this,
			'Products',
			'Product',
			array('Productname'=>'Productname','Imagename'=>'Imagename','Presentation' => 'Presentation','Contenance' => 'Contenance','Price' => 'Price'),
			'getCMSFields_forPopup'
		
		));

	$f->addFieldToTab('Root.Content.ActifsProduct', new HtmlEditorField('ActifsProduct'));
	$f->addFieldToTab('Root.Content.OtherProducts', new HtmlEditorField('OtherProducts'));
	$f->addFieldToTab('Root.Content.TextProduct', new HtmlEditorField('TextProduct')); 
	$f->addFieldToTab('Root.Content.GestesProduct', new HtmlEditorField('GestesProduct')); 
	$f->addFieldToTab('Root.Content.SecretProduct', new HtmlEditorField('SecretProduct')); 
	$f->addFieldToTab('Root.Content.Main', new TextField('ImageName'), 'Content');
	  $f->addFieldToTab('Root.Content.Main', new TextField('FlashName'), 'Content');
	  $f->addFieldToTab('Root.Content.Main', new TextField('FlashWidth'), 'Content');
	  $f->addFieldToTab('Root.Content.Main', new TextField('FlashHeight'), 'Content');
	  $f->addFieldToTab('Root.Content.Main', new TextField('LayoutType'), 'Content');
	  
		
		return $f;
	

	}


 
}






	class ProductPage_Controller extends Page_Controller
{





public function index() {
return Director::redirect($this->Products()->First()->Link());
}

 public function FlashVar() {
return "myFlashVar=$this->ImageName";
 }

  public function FlashVarName() {
return "FlashVarName=$this->MenuTitle";
 }

static $allowed_actions = array (
'show'
);
public function show() {
return array (
'Product' => DataObject::get_by_id("Product",$this->urlParams['ID'])

);
}

}

and then following your explanations in http://silverstripe.org/template-questions/show/289897?start=0#post290447

I created ExportProductPage_show.ss in export/ folder

since ProductPage_show.ss is my template

Now after flush this what i get :

If I do :
http://mysite/products/productname/show/export
i get the error
user_error("DataObject::get_by_id passed a non-numeric ID #$id", E_USER_WARNING);

If I do :
http://mysite/products/productname/show/5/export
i get the regular page

If I do :
http://mysite/products/productname/export
i get the error :
Action 'export' isn't allowed on class ProductPage_Controller

I hope you can help me because I'm a bit lost ;)

Thanks

Avatar
bummzack

Community Member, 904 Posts

27 August 2010 at 7:16am

Edited: 27/08/2010 7:17am

Regarding your first reply: If the surrounding node is the same as one of the child-nodes, then you're probably inside the second level of your site already? Maybe you'll have to use Parent instead:

<?xml version="1.0" encoding="UTF-8"?>
<% control Parent %>
<node id="$ID" label="$Title" link="$Link" classname="$ClassName">
<% end_control %>
<% control Menu(2) %>
$ExportContent
<% end_control %>
</node>

Regarding your last post: I think you're starting to mix things up or you do things way too complicated.
Why not just create a template templates/export/ExportProductPage.ss.. this will allow you to integrate the ProductPage in your XML export.

Over the last few posts, the topic of this thread has moved to something entirely different. The solution I originally proposed was meant as a solution to export the whole site-tree to XML. It isn't a silver bullet for all template related problems and I think currently, you're really doing stuff way too complicated where you could simply use a normal template...

I also don't understand what your needs are exactly.. maybe you should explain better what you need and then try to figure out an optimal solution. Also: keep things simple... once you got something working you can still tweak it for performance (if that's really necessary).