Passing a variable

Hi all,
I’m using V8.5.9 and I have what I think is a simple question. My php skills are not that great so please be gentle on me. I have a website that I hand coded years ago. I want to move it over to Concrete. One of my pages draws a map based on a variable passed to the page from a menu item. “res.php?area=Y_east”
What is the easiest way to pass that variable. Can I just do what I’ve been doing? Or should I do something differently.

hi @baxterdmutt Here are some [instructions on how to pass data to a URL]
(Example: Passing Data from a custom URL into a Block's View Layer) is this what you are looking to do?

jessicadunbar answer is good if you want to have multiple instances of map blocks on page.

If you want to only have one instance of map (or not in block), I think passing variable through url is still good option.

Remember to turn off “Full page caching” on that page/caching in block, since page/block would be cached only once (and ignoring query strings when cached).

// In views:
$request = \Concrete\Core\Http\Request::createFromGlobals();
$area = $request->query->get('area');
// In controllers you can use:
$area = $this->request->get('area');
// If everything fails, you can always use standard PHP syntax (but still I suggest using examples above)

I have no idea where I would put any of that code. Sorry to sound so dumb but that’s the problem I’ve been having understanding any of the examples and explanations in the ConcreteCMS docs. They all assume we are all php developers. For example: “Just create a method…”. Ok I understand methods and what they are, but where do I create this method. It’s assumed everyone knows how do do this sort of stuff.
Could I get just a little bit more direction please? Thanks.

Ok I don’t know why I could find this before but I found how to add a controller. I still can’t see how to add a view.

Well, it depends how verbose/complicated your code is/how many location you want to add.
Without coding, you could just add multiple pages and use built-in Google Maps block (and fill it with proper coordinates).
This way:

  • one page (you can create your own page type in Dashboard UI) = one map,
  • you will have nice urls for SEO (like “/places/my-first-place” etc.)
  • you can now automatically generate “Page lists” and “Autonav” blocks based on your Sitemap
  • optionally you could create you own custom template for block
  • optionally you could replace Google Maps block with something from Marketplace

But if you really need something custom made, there are multiple ways to do it:

  • Create Single Page Controller/Single page view file
  • Create Page type Controller/Page template in theme folder
  • Build it as custom block*
  • Build it as custom package (with block included)

*You can create custom block with this package:

Generated custom block will be put into application/blocks folder. Inside you will find your controller.php (with view() method) and view.php.

Controllers and views are concepts shared among many things in Concrete.
I strongly suggest to learn about overall concepts from “Editor” docs and then look for solutions how to create custom stuff in “Developer” docs.
Especially how you can leverage Page Types, just by clicking everything in UI.

If you can’t modify/access theme folder (for example you are using theme from marketplace), then using blocks is probably the easiest way to go.

Ok, maybe I didn’t make my question clear. Figuring out how to code the map is not the question. The question is what’s the best way to pass a variable. Can it be passed the old fashion way by just passing it as whatever.php?area=Y_east in the link. Like “http://my
My plan was to just code the php script I used before, into a block and pull the variable in. Will the variable passed into be link be ignored? Or will that work ok each time.

Sure, you can.
But remember to set $btCacheBlockOutput to false at the top, because otherwise block will be probably cached and ignoring query string.
Also Full page caching in Dashboard should be set to “If blocks allow it”

1 Like

I’m sorry but does $btCacheBlockOutput go at the top of the block?

Yes, you can check core blocks to see where exactly.