Comments (2)
Hm I messed around a bit and thought I could for testing purposes extend your applySrcSet
function.
I found this post in the forum and thought something like this should work:
/**
* @param $value
* @return array
*/
public function applySrcSet($value): array
{
$srcset = \Kirby\Toolkit\A::get($this->options, 'srcset');
if (! $srcset) {
// $value['srcset'] = null; // NOTE: not setting is better for frontend than `null`
return $value;
}
$file = $this->kirby->file($value['id']);
$value['srcset'] = $file->srcset($srcset);
$c = $file->content();
foreach ($c as $key => $value) {
if ($key == "fields") {
foreach ($value as $field) {
$value[$field] = $file->$field();
}
}
}
return $value;
}
Unfortunately nothing happens. Also I can' t really test things by printing a few values to the screen, because as soon as I don't return json I get an error
"message": "Return value of Robinscholz\\Betterrest::applySrcSet() must be of the type array, string returned",
what I found out is:
$c = $file->content();
var_dump($c->data());
If I use this I see that the fields are within this data()
which I've never seen in kirby before...
I'll try to keep digging though....
Funnily this works:
// within your function applySrcSet where I have access to the file:
$c = $file->content();
$value['alt'] = $c->alt();
This will give me my alt value like:
"alt": {
"value": "My alt text"
}
Not exactly how I want it. But still I don't understand why the for-each loop above would not work...
I realized that something like
$c = $file->content();
foreach ($c as $key => $value) {
if ($key == "data") { // here I should check for data instead of fields...
foreach ($value as $field) {
$value[$field] = $c->$field(); // but this does not help at all
}
}
}
from better-rest.
I see a few problems with this. Since you don’t know what someone will put into their files blueprint, you can’t really predict if the content needs to be simply returned or transformed as well with i.e. kirbytags or smartypants.
Since this would slow response times, it would need to be included as a seperate option, turned off by default. Hooking into the srcset function is also a bit obscure.
Since you can already fetch this info with a seperate api call to i.e. /rest/pages/:id/files
, I don’t see the need to include this for now. However, feel free to submit a PR!
from better-rest.
Related Issues (12)
- Add markdown parsing HOT 1
- srcset generation breaks with Kirby 3.5.0's layout field
- Kirby crashes on latest version when plugin is installed as git submodule HOT 7
- [Question] Using image transforms (resize) in Kirby Blocks HOT 1
- [Question] Using Betterrest Class method to JSONify a structure field HOT 1
- Kirby Image Blocks crashes Betterrest HOT 3
- [Question] Do you support pagination? HOT 1
- Documentation a bit unclear – how do I see this plugin taking effect? HOT 8
- How to use Multilang? How to send an X-Language header? HOT 1
- Improvement: Kirby Toggles seem to be transformed from Booleans to strings – Keep Booleans HOT 3
- Date format is corrupted by non-breaking space HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from better-rest.