Giter Club home page Giter Club logo

Comments (2)

Jones-S avatar Jones-S commented on May 31, 2024

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.

robinscholz avatar robinscholz commented on May 31, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.