Jump to content

image url path inside php tag, how is this possible with processwire?


danielholanda
 Share

Recommended Posts

I have this form in my html which works perfectly locally. Once I had this as a template my form doesnt work well. This has a calendar button available and here is the problem. I already had this php applied:

<?php
$myCalendar = new tc_calendar("date3", true, false);
$myCalendar->setIcon("_php/calendar/images/iconCalendar.png");
$myCalendar->setPath("_php/calendar/");
$myCalendar->setYearInterval(2012, 2022);
$myCalendar->dateAllow('2012-08-30', '2022-08-31');
$myCalendar->setDateFormat('j F Y'); 
$myCalendar->writeScript();  
?>

This means that I would have to paste this code which I have applied to any inner url I have in the html such as this example:

<input type="image" src="<?php echo $config->urls->templates?>_img/submit_button.png" id="input_img" name="submit" />

I've tried inserting only echo $config->urls->templates?. This way:

<?php
$myCalendar = new tc_calendar("date3", true, false);
$myCalendar->setIcon("$config->urls->templates_php/calendar/images/iconCalendar.png");
$myCalendar->setPath("$config->urls->templates_php/calendar/");
$myCalendar->setYearInterval(2012, 2022);
$myCalendar->dateAllow('2012-08-30', '2022-08-31');
$myCalendar->setDateFormat('j F Y'); 
$myCalendar->writeScript();  
?>

If I wanted the url to work how should I do it with processwire?

Link to comment
Share on other sites

If what Antti said above has been taken care of at some point, this might be the problem here:

$myCalendar->setIcon("$config->urls->templates_php/calendar/images/iconCalendar.png");

Try doing it this way instead:

$myCalendar->setIcon("{$config->urls->templates}_php/calendar/images/iconCalendar.png");

Of course that would only work if the path for this particular icon is /site/templates/_php/calendar/images/iconCalendar.png.

Link to comment
Share on other sites

Hello Teppo and Apeisa,

Yes, the calendar I'm using is not part of processwire. I have this file in the inner html (I dont know how you call this honestly) so I will place a picture of my path. I already tried the code you told me:

<td>
<?php
$myCalendar = new tc_calendar("date3", true, false);
$myCalendar->setIcon("{$config->urls->templates}_php/calendar/images/iconCalendar.png");
$myCalendar->setPath("{$config->urls->templates}_php/calendar/");
$myCalendar->setYearInterval(2012, 2022);
$myCalendar->dateAllow('2012-08-30', '2022-08-31');
$myCalendar->setDateFormat('j F Y'); 
$myCalendar->writeScript();  
?>
</td>

I will upload two pictures. One with the result I have once I put this code and the desired effect. Form.calender is how I have it working with the same path on my html/css. Form.code is the result after placing your code+

I will upload two pictures. One with the result I have once I put this code and the desired effect. Form.calender is how I have it working with the same path on my html/css. Form.code is the result after placing the same code into the CMS and placing the code above.

I just dont understand why it doesnt work if on my html/css and seen with MAMP its perfect and once applying it into processwire it doesnt work. Its a php file which has nothing to do with processwire...

Really, thank you for the help!

post-663-0-95533900-1347351075_thumb.png

post-663-0-66518300-1347351273_thumb.png

post-663-0-98413800-1347351283_thumb.png

Link to comment
Share on other sites

Maybe it helps but I just observed that at the begginingn of the html I have this code to initialize calendar:

<?php
require_once('_php/calendar/classes/tc_calendar.php');
?>

I;ve tried to put {$config->urls->templates} in all cases and it still does not work correctly. Therefore there are three url inside a php which are giving me problems. I thought that I didnt had to do anything with the url as its inside the php I dont need to redirect it with {$config->urls->templates}.

i really dont know how to follow up... Thanks if somebody can help me.

Link to comment
Share on other sites

There's two configs for urls and paths.

$config->urls->... returns web urls

$config->paths->... returns web server path

Mainly for frontend code like including css and script or image you would need ->urls

For including libraries or using file_exists, you can take ->paths

Also check out the cheatsheet I've done, that will give good reference over the api. http://www.processwire.com/api/cheatsheet/

  • Like 1
Link to comment
Share on other sites

I write here to let you know I found an answer to my problem so if anybody has something similar look here.

First of all you don't need to add any prefix inside a path inside a php created by you. It works as the path written by you. So adding {$config->urls->templates}. before the path doesnt make any difference. My problem was the following...

I learnt that a php process cannot occur inside the templates folder. Basically what you need to do is to put the folder with the process, so in my case folder _php containing all the relevant data, outside this folder. For example as I did inside /site/. Redirect the path and everything should work.

Dani

P.D. Really thanks to everybody who helped. Especially the cheatsheet you sent. All that is very valuable data.

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.
  • Similar Content

    • By theExo
      Hey folks,
      im pretty new to Processwire. A client of mine asked me to migrate his old (v2.5) Processwire Website. On his server its running on PHP 5.3 and i want to upgrade + migrate the site at the same time. I Downloaded the Site from his server to set it up locally, replaced the /wire directory, index.php and .htaccess with the files of the latest version. After that i changed the DB Connection details in the config.php, swapped to PHP 7.4 and now, when i open up the site on my localhost i get this error:
      compile(\ProcessWire\wire("config")->paths->root . "site/templates/includes/head.inc.php",array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)))?> compile(\ProcessWire\wire("config")->paths->root . "site/templates/includes/header.inc.php",array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)))?> compile(\ProcessWire\wire("config")->paths->root . "site/templates/includes/start_content.inc.php",array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)))?> compile(\ProcessWire\wire("config")->paths->root . "site/templates/includes/footer.inc.php",array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)))?> The page itself doesnt load, just a white space with this stuff on it
      I checked if the files exist, they do.
      I hope anyone can help me with that 🙂 Thanks in advance!
    • By Liam88
      Hi,

      After years of just playing around with Processwire I have asked 3 q's in the same week. It's all about working with forms, parameters etc and so I'm hoping this ordeal is nearly over!
      I currently have a checkbox filter:
      <form id="abFilter" method="get" role="form" action="'.$page->url().'"> <div class="list-group"> <h3>Content Type</h3>'; $cont = $fields->get('ab_content'); $contents = $cont->type->getOptions($cont); foreach($contents as $ab_cont){ echo' <div class="list-group-item checkbox"> <input type="checkbox" class="" id="'.$ab_cont->title.'" name="content" value="'.$ab_cont->title.'"'; if (in_array($ab_cont->title, $contArray)){ echo "checked"; } echo'> <label for="'.$ab_cont->title.'">'.$ab_cont->title.'</label> </div>'; } echo' </div>'; //end of filter 1 //start of filter 2 echo' <div class="list-group"> <h3>Channels</h3>'; $chan = $fields->get('ab_channels'); $channel = $chan->type->getOptions($chan); foreach($channel as $ab_chan){ echo' <div class="list-group-item checkbox"> <input type="checkbox" class="" id="'.$ab_chan->title.'" name="channel" value="'.$ab_chan->title.'"'; if (in_array($ab_chan->title, $chanArray)){ echo "checked"; } echo'> <label for="'.$ab_chan->title.'">'.$ab_chan->title.'</label> </div>'; } echo' </div>'; ?> <button id="select">Get Checked Checkboxes</button> </form><!-- end of form --> I also have a piece of script which selects all the checkboxes and then outputs them into readable parameters for the URL which then passes into the $inputs. The reason for the script is to not have duplicate filters like ?ab=1&ab=2 and the script changes it to ab=1_2 which on the input gets exploded into an array. 
      document.querySelector("form").onsubmit=ev=>{ ev.preventDefault(); let o={}; ev.target.querySelectorAll("[name]:checked").forEach(el=>{ (o[el.name]=o[el.name]||[]).push(el.value)}) console.log(location.pathname+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&")); document.location.href = location.pathname+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&"); } Here is $inputs and so on on the page:
      //Default selector to get ALL products $baseSelector = "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2"; $selector = "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2"; $input->whitelist('channel',explode("_", $channel)); // Use this to append to the $items filter if($channel){ $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } $test = $pages->find($selector); // This is just testing if the $selector choise returns and if not use page filter without filters. if(count($test) > 0){ $items = $pages->find($selector); // $items with the parameter filter // Example - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2,ab_channels=facebook-ads" // Example (multi choice) - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2,ab_channels=facebook-ads|instagram-ads" // Example (with other filters) - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2,ab_channels=facebook-ads,ab_content=video|static" }else{ $items = $pages->find($baseSelector); // Example - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2" } $total = $items->getTotal(); I have stripped out a few of the other filters from the above to try keep it a little more concise (haha). Now I appreciate the post may be long but here we are at the end!
      The URL I get on page 1 of the filter results would look like: example.com/blog/?channel=facebook-ads_instagram-ads
      If I click page 2 the url changes to - example.com/blog/page2/?channel=
      If I then click back to page 1 it changes to - example.com/blog/?channel=
      So I'm hoping you can see my problem and hoping someone can assist. I need to work out how to keep the parameters in the url but also if I remove that filter for that parameter to remove.
      This whole process works without pagination but with pagination it has a different behaviour.
      Thank you in advance
    • By OrinTerry
      Hello everyone. I am running a small technology blog, which is in WordPress. The main problem with my blog is that it does not open on any Windows 7 computer normally. I know Windows 7 has lost official support from Microsoft but still, there are plenty of users who still use Windows 7. The blog site is already 'HTTPS' protected but after opening in any browser, it shows 'not protected' next to the URL box. So, if I migrate all the site data to 'ProcessWare', will I get the same problem here too? Any kind of feedback would be greatly appreciated.
    • By Marvin
      Hello, excuse me
      I'm new at processwire, i want to ask about a master detail system (Inheritance system) using a processwire. Can we create a Inheritance table using a processwire, and how we create it? Thank you for the help
    • By pideluxe
      From the recent discussion about the roadmap & wishlist for 2021 and some other posts by @ryan, it comes to my mind that developing and coordinating the whole project for one person is becoming harder and harder and leads nearly to the reverse of expanding the ProcessWire ecoysystem. This is not against Ryan, i think everyone here knows how engaged he is about ProcessWire, but he has only 24/7 (sometimes i think he's got far more than that...). 
      We as the community could support the project (financially) to relieve Ryan and could take over some tasks from him. This could be, but is not limited, to:
      Building a Foundation/Association/Company to ensure the persistence of the project and to fund the work put in ProcessWire of Ryan (and others). Nearly every other CMSs i checked has something like this (Drupal Association, Typo3 Association, Joomla Foundation, Wordpress Foundation, Contao Association, ...). This also puts more trust in the project, if someone new will check on his engagement in ProcessWire. Assigning persons/teams to work on things: Extending the core (when necessary) Developing and maintaining major modules (e.g. page builder, admin themes, internationalization, marketing, ecommerce system, ...) Testing and inspection of modules developed by others Making translations of modules (translation of the core is mostly covered, i think) Working on PRs & issues submitted on github Working on the homepage Coordinating the community efforts I know, some resorts are already covered by others (e.g. @Pete for the forum, @horst for images, ... ), but there are many other areas where this ist not the case. By joined efforts by the ProcessWire community this hopefully will also attract new developers to the system and by a growing number of users this assists in the things above in a circular process. What do you think? 
×
×
  • Create New...