# |
Jul 11th 2017, 09:11 |
savant |
since the file will be stat’d once |
# |
Jul 11th 2017, 09:11 |
savant |
there is minimal overhead on including another file |
# |
Jul 11th 2017, 09:11 |
jonasz |
thx, that is exactly what i was looking for ;) |
# |
Jul 11th 2017, 09:11 |
savant |
again, as @glanceded said, elements or helpers would be better suited to this problem |
# |
Jul 11th 2017, 09:11 |
savant |
which is better done at the user-level |
# |
Jul 11th 2017, 09:10 |
savant |
its just not possible to do what you’re asking without some hokey-pokey extra logic |
# |
Jul 11th 2017, 09:10 |
savant |
(or whatever the equivalent is |
# |
Jul 11th 2017, 09:10 |
savant |
`echo str_replace('some_var', 'derp', $this->fetch('sidebar'))` |
# |
Jul 11th 2017, 09:10 |
jonasz |
aha, i get u now |
# |
Jul 11th 2017, 09:10 |
savant |
but then, why cant you just do the following |
# |
Jul 11th 2017, 09:10 |
savant |
for instance |
# |
Jul 11th 2017, 09:09 |
savant |
`{{some_var}}` |
# |
Jul 11th 2017, 09:09 |
savant |
so we’d need to come up with some alternative syntax for embedding variables |
# |
Jul 11th 2017, 09:09 |
savant |
not when you call `$this->fetch('sidebar', ['some_var' => 'derp']);` |
# |
Jul 11th 2017, 09:09 |
savant |
as is, the `$some_var` is interpolated at the time of the entire template inclusion |
# |
Jul 11th 2017, 09:08 |
savant |
lets say you want to use that element elsewhere |
# |
Jul 11th 2017, 09:08 |
savant |
$this->start(‘some-element’); echo “derp ${some_var}“; $this->end(); |
# |
Jul 11th 2017, 09:07 |
savant |
consider the following |
# |
Jul 11th 2017, 09:07 |
savant |
we cant really do that |
# |
Jul 11th 2017, 09:07 |
savant |
adding a third argument would mean interpolation |
# |
Jul 11th 2017, 09:07 |
savant |
in order to use one |
# |
Jul 11th 2017, 09:07 |
savant |
you dont need to share an element |
# |
Jul 11th 2017, 09:07 |
jonasz |
i get your points, but still, I think adding 3rd argument to fetch(), so it acts a little bit as an element, would enrich capabilities of framework slightely. that would suit one particular case where u don't share a snipet between multiple views/layouts ;) aloso loading element is additional overhead - reading new file etc. thx for advice |
# |
Jul 11th 2017, 09:03 |
savant |
(usually) |
# |
Jul 11th 2017, 09:03 |
savant |
so you can trust my advice |
# |
Jul 11th 2017, 09:03 |
savant |
if it helps give some strength behind my argument, I’m one of the cakephp core developers |
# |
Jul 11th 2017, 09:03 |
savant |
easiest of the three to setup - just one extra file - and you can assign the output of the element to a view block if you really needed it |
# |
Jul 11th 2017, 09:02 |
savant |
i would go with an element |
# |
Jul 11th 2017, 09:02 |
savant |
those are your options |
# |
Jul 11th 2017, 09:02 |
savant |
- use a helper |
# |
Jul 11th 2017, 09:02 |
savant |
- use an element |
# |
Jul 11th 2017, 09:02 |
savant |
- use a view cell |
# |
Jul 11th 2017, 09:02 |
savant |
if you want conditional output, you’ll need to either: |
# |
Jul 11th 2017, 09:02 |
savant |
that value can be a single character or a lot of html |
# |
Jul 11th 2017, 09:02 |
savant |
and then pull the value out |
# |
Jul 11th 2017, 09:02 |
savant |
you assign a value into them |
# |
Jul 11th 2017, 09:02 |
savant |
viewblocks arent meant for what you are trying to use them for |
# |
Jul 11th 2017, 09:01 |
savant |
if its too small to dedicate, just make your viewblock wrap around a for loop instead |
# |
Jul 11th 2017, 09:01 |
savant |
a helper would also be a good fit |
# |
Jul 11th 2017, 09:01 |
glanceded |
I think you need a helper. check out this page https://book.cakephp.org/3.0/en/views/helpers.html#creating-helpers |
# |
Jul 11th 2017, 09:00 |
jonasz |
because it is small thing, and far too small to dedicate separate file for it. i'm applying x-editor UI to two text elements on my page - it is basically rendering some js code around them. the only vriable is the db field name. currently i chave to copy/paste it in the view - like 6 lines of code. I would prefer to have it in separate block |