How to get theme path into the edit.php file??

Permalink
I am trying to pull in the theme path value into the edit.php file of a block I have created to no avail.

C5 is driving me crazy today!

How in the world do I get that value into edit.php?

I've tried everything.

I've created a function edit() inside the controller and tried setting the value returned by getThemePath() method of the View::getinstance()

I've tried accessing things directly in edit.php.

I've Googled for hours and looked all over this forum.

Nothing.

Here is what I presently have inside my edit.php file.

<?php
$v = View::getInstance();
$themePath = $v->getThemePath();
echo "Theme Path = ".$themePath."<br>";
$themePath = $this->getThemePath();
echo "Theme Path = ".$themePath;
?>


That's not working either. Nothing. No value.

Anybody got any clue as to how I might be able to get this value into my edit.php file??

I need the theme path so that I can read where the typography.css file is at and use that css file in a new content editor block I am creating.

Carlos

 
12345j replied on at Permalink Reply
12345j
try something like this
$v = View::getInstance(); 
$handle = $v->getThemeHandle();
$theme = PageTheme::getByHandle($handle);
$theme->getThemeURL();
//might want to use $theme->getThemeDirectory() here, don't know exactly
carlos123 replied on at Permalink Reply
Hi 12345j,

Thanks for that. I will try what you suggest.

What I don't understand is why $v->getThemePath() doesn't work.

I mean it does work in the sense that $v->getThemePath() returns the correct value when used inside an edit() function in the controller but even when it does, for some strange reason I cannot assign that value to be available to the edit.php file through the $this->set('themePath', $v->getThemePath()) line inside the edit method of the block controller.

$themePath ends up being completely empty inside the edit.php file.

Gosh I hope the above makes sense as it will sound like absolute gibberish to anyone who has dealt mainly with the admin interface on this sort of stuff.

Anyway...I'll try what you said 12345j though I have a hard time understanding why I must get the value I need in such a roundabout way as to get the theme handle and all that when there is already a method that should provide that to me.

I wish there was some documentation somewhere that actually laid out what objects are available to what file in a block instead of my having to ask questions here or my having to spend hours searching for answers and experimenting in the code to try and access objects and methods that may or may not exist.

This is the biggest single, pain in the butt, thing about C5. The lack of such documentation. More than once I have thought of going back to WordPress over this one issue alone.

But I trudge on with C5 as I already have quite a bit of time invested in using it.

Carlos
carlos123 replied on at Permalink Reply
Just to be thorough...the following does not work when put into the controller for the block...

public function edit() {
      //xdebug_print_function_stack();
      $v = View::getInstance();
      echo "\$v->getThemePath() = ".$v->getThemePath();
      $this->set('themePath', $v->getThemePath());
   }


$themePath (the variable set by the set() method) ends up empty when accessed through edit.php

Likewise in the above code $v->getThemePath() returns an empty value.

Still trying to get this.

Carlos
carlos123 replied on at Permalink Reply
None of this works either when put into the block controller.

public function edit() {
      //xdebug_print_function_stack();
      $v = View::getInstance();
      $handle = $v->getThemeHandle();
      $theme = PageTheme::getByHandle($handle).$themeDir;
      echo PageTheme::getByHandle($handle).$themeDir;
      echo "<pre>";
      print_r($theme);
      echo "</pre>";
      echo "Theme directory is: ".PageTheme::getThemeDirectory();
      //$v = View::getInstance();
      //echo "\$v->getThemePath() = ".$v->getThemePath();
      //$this->set('themePath', $v->getThemePath());
   }


Nothing. Just blank all around.

$theme is shown to be nothing in the print_r statement. PageTheme::getThemeDirectory() returns nothing. $themeDir is nothing.

All nothing.

Coming up empty. Looking around to see what else I can try. This is getting so ridiculous that I am thinking of just saving the value in any way I can get it, opening the file within edit.php, and reading that value in where I need it. Bypassing the MVC spaghetti altogether!

Like a blind man groping around trying to figure out where the lightswitch is at. That's how I feel trying to grope around in the code to find out how to get the value I need through this MVC business.

How anybody can code with this approach in a way that is not overly time consuming (trying to figure out what is where and what is what) is beyond me.

Carlos
carlos123 replied on at Permalink Reply
Hi 12345j,

The line "$theme->getThemeURL();" produces the error "Fatal Error: Call to a member function getThemeURL() on a non-object..."

I assume that means that $theme is not an object that can be used to reference the getThemeURL() or some such.

Tracking down where I can access getThemeURL() from (yet more code digging...sigh).

Carlos
Phallanx replied on at Permalink Reply
Phallanx
@carlos123

"Bypassing the MVC spaghetti altogether!"

Pretty much the conclusion I came to. My addon now uses only the controller and the view and the getting of directories are functions in the controller based on the dirname(__file__) of the controller ('cos there is an example of getting the package). Wait until you get to the point where everything works EXCEPT it only updates every other refresh...lol

MVC = Muddle Verbose Confuser

To use this effectively (the api) you have to know it inside out (or have the api manual) .... and I really can't be bothered trawling through the core any more for doing something as trivial as a package.
carlos123 replied on at Permalink Reply
I am seriously considering going back to WordPress.

I mean yes...their user interface is a bit more complicated for computer or internet illiterate end users but working with their code is ten times easier than this MVC sphagetti stuff.

The whole reason I switched to Concrete5 was that it seemed that their code was easier for me as a web developer to work with and modify.

Little did I know.

If this is how difficult it is to get something as relatively benign and simplistic as the path to the theme from within a block's edit.php file...goodness gracious! Am I going to have to go through this kind of time consuming thing to figure out how to get this or that other tid bit of information?

Utterly ridiculous. Trying to figure out what a CMS does should not be this incredibly difficult.

Carlos
12345j replied on at Permalink Reply
12345j
hey carlos- sorry. I may have been misleading you in an earlier post that (incorrectly) answered. Try doing this-
$this->set('test','test');
. I doubt that will work in the edit of a block, right? instead of using the edit() function, try using the on start -
public function on_start() {
         $this->set('test', 'test');
      }
Does that work? if so, declare stuff in your on_start in the package controller. (whats in your original post should work) Apologies again for misleading you in another post.
carlos123 replied on at Permalink Reply
Okay...first off the following works...

Inside controller.php...

public function on_start() {
   $this->set('test', 'test');
}


Then inside edit.php...

<?php echo $test; ?>


The result correctly echoes 'test' to the screen on an edit of the block.

So far so good.

Now this doesn't work...

Inside controller.php...

public function on_start() {
      $v = View::getInstance();
      echo "Theme Path inside controller.php is: " . $v->getThemePath() . "<br>";
      $this->set('themePath', $v->getThemePath());
   }


In the above the echo line correctly outputs the theme path when the block is VIEWED (capitalized for emphasis) but NOT when it is edited.

Nor does the themePath variable created by the set() method show up inside edit.php when the block is edited.

So yes...set()ing a test variable is accessible within the edit.php file as $test but set()ing a themePath variable based on the value that normally gets returned by getThemePath() does not in that $themePath is completely empty inside edit.php.

Any other ideas anyone?

I think I will complete my present project with my client using C5 and will then go back to using WordPress or perhaps my own CMS for future projects (which I left half way done to use C5 instead). This MVC stuff just seems like a bunch of nonsense to me at this point. Seriously.

For all it's hype it just result in incredibly hard to follow and understand code which pulls values out of thin air. Values that come from who knows where. Code gets split up into a thousand pieces that seem to execute in a disjointed manner all over the place.

Hard to follow, hard to maintain, hard to modify code which throws out modular and easy to work with programming principles...just makes my life as a web developer all that much harder. I don't need the headache.

I personally prefer straight HTML, PHP, and CSS or using my own created OOP classes of reusable code than this.

Thanks for your attempt to help me out 12345j.

I hate to leave my client hanging with C5 and may offer to do a conversion from c5 to WordPress for him at no charge chalking this up to a learning experience for myself.

I may still develop a block or two for C5 and contribute it to the MarketPlace here to see how they do but as for a CMS of choice? Nope. Not for me at this point.

Carlos
codingpenguins replied on at Permalink Reply
Maybe you used the variable themePath in your block. Do you run different code for edit or view? Here is my code
public function on_start() {
      $v = View::getInstance();
      echo "Theme Path inside controller.php is: " . $v->getThemePath() . "<br>";
      $this->set('themePath', $v->getThemePath());
   }

Then view
echo " Theme from view:".$themePath." ";

Works in edit and view. Attached to screenshot of edit.

EDIT: I just realized you were referring to the edit.php file not edit mode. Testing now.

EDIT: You cannot pass straight into the add.php or edit.php, but you can use javascript or ajax to do so.

See these forums:http://www.concrete5.org/community/forums/customizing_c5/ajax-from-... orhttp://www.concrete5.org/community/forums/customizing_c5/pass-varia...

Hopefully this helps you
carlos123 replied on at Permalink Reply
Hi codingpenguins.

I appreciate your input but...well...like I said I have not found a way to get the theme path (i.e. the value) into the edit.php file for my use there.

This has absolutely not one thing to do with Ajax or passing controller available values into Javascript or anything of the sort. I am just trying to get the value of getThemePath() (in whatever class will give me that value) as gotten in the controller in whatever method there you please (i.e. edit, on_page_load, etc..) ...into my edit.php file (nothing to do with edit mode or other such thing).

A value from the controller (i.e. the path to my theme) into my edit.php file.

If you read through this thread (and by no means do I expect you to do that but if you are curious rather...) you will see the various code snippets that I have tried and that don't work.

Carlos
codingpenguins replied on at Permalink Reply
Well save it to the database of that block on load, I think this is a hack, but its the best I can do, since the only thing available in add.php and edit.php are the database items of that block, just save it to the db as a varchar and just call it themepath in the database and in the edit.php or add.php use $themepath to pull the value.

EDIT: I read through some of it and I thought it was interesting but, I tested it so I saw the issue you were having. I suggested passing it through javascript or ajax, not that you were doing it.
carlos123 replied on at Permalink Reply
Hi codingpenguins.

I had already thought that saving the value of getThemePath to a text file and then reading that in into the edit.php was the only way to go so your database saving solution is another way to do that for sure.

I am curious however codingpenuins. You said...

"the only thing available in add.php and edit.php are the database items of that block".

Yet if I include the following line inside the controller file, say inside the on_start method (or whatever that method is called)...

$this->set('test', 'test');


That works perfectly fine to set a variable called $test which is then available from inside edit.php (at least that one for sure as I have not tested it elsewhere).

How does that little bit of "magic" line up with your statement that nothing else but database values is available outside the block controller?

Carlos
codingpenguins replied on at Permalink Reply
LOL magic! I did not look at the code but only assume, and playing around with it, it looks like all variable sets do not get set or even reused. But if you do
$test = 'testing';
$this->set('test', $test)

does work but setting test to a variable does not. I really am curious to go though all the code, but makes me believe that add.php and edit.php runs different than the controller.php does... At this point I am not even sure if the file thing or database thing will work if you add the code to the onstart.
carlos123 replied on at Permalink Reply
When I said setting test to a variable I meant...

That in the following code snippet...

$this->set('test', 'test');


...you are creating a variable called "test" accessible within edit.php by "$test".

A variable called "test" that you are set()ing to the value of...well...'test'.

That's what I meant.

Carlos
carlos123 replied on at Permalink Reply
This is why I have given up on using Concrete5 to build web sites with. It's just too much of a pain to try and figure all this out when I need to figure it out.

I mean if you are not sure (and you sound like you have more experience in it than I do) where does that leave me? LOL

Oh well...thanks for your input anyway codingpenguin.

Carlos
nicwolff replied on at Permalink Reply
Can you use the absolute themeDirectory instead of the relative themePath?

<?php 
    $p = Page::getCurrentPage();
    $t = $p->getCollectionThemeObject();
    $themeDir = $t->getThemeDirectory();
?>