Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    What’s your js?
    Romain
    @Romaixn
    Yes I have that..
    My JS is simple :
    data = {
                'action': 'see-more-ajax-action',
                'query': loadmore_params.posts,
                'page': loadmore_params.current_page
            };
    
            $.ajax({
                url: loadmore_params.ajaxurl,
                type: "POST",
                data: data,
    I have a 200 status code but returned '0' in success function
    codemonkeynorth
    @codemonkeynorth
    what does loadmore_params.ajaxurl equate to?
    oh you're doing a POST... but your route is get().. either use route()->post()->.. or route()->any()->...
    Romain
    @Romaixn
    ooooh... my bad of course
    Indeed it's work, thanks a lot for that
    codemonkeynorth
    @codemonkeynorth
    @Romaixn no worries . I learned something. Whaf is your ajaxurl tho? Is it just pointing to wp-admin/admin-ajax.php ?
    Piotr
    @piotrku

    The situation is like this:
    I pass all front-end requests through WPEmerge - MyApp::route()->all() so when I invoke some regular page, a view wp-content\themes\my-theme\views\page.php is automatically displayed.

    I'm wondering how to achieve this:
    I like this route -> controller -> view schema, but I don't want to create routes for all standard WP URLs .
    I'd like to have some controller(s) in the middle to inject some data (variables) when needed to some of the standard-route-views.
    How can I create a controller that would be automatically invoked for those standard WP routes before (in this case the page.php) view is served?
    Should I use middleware for that? One method that would check what route is this and delegate handling of this request to some dedicated classes?

    Atanas Angelov
    @atanas-dev

    If you want to inject some data into a view regardless of how it is rendered you can use View Composers which do just that: https://docs.wpemerge.com/#/framework/views/view-composers

    There's an article on the subject that you may find useful as well - it uses outdated syntax but the concepts are the same: https://wpemerge.com/2019/01/24/view-composers-passing-data-and-staying-dry/

    Alexander
    @xenx-efy
    Hello. I noticed that if I register an image import '@images/progress.svg', it goes to the fonts folder, not the images. How can this be corrected? Or maybe I'm doing something wrong?
    Alexander
    @xenx-efy
    And also puts it in the "Images" folder, but in this form: export default __webpack_public_path__ + "fonts/mountains.59dff4a121.svg";
    codemonkeynorth
    @codemonkeynorth
    Is it breaking anything?
    Alexander
    @xenx-efy
    yes, I cannot get svg images from images folder
    it is a little not logical
    codemonkeynorth
    @codemonkeynorth
    I mean doesn’t the path resolve in your code so it just pulls it from your fonts folder and shows up anyway?
    or are you getting a 404
    Alexander
    @xenx-efy
    I'm using this construction App::core()->assets()->getAssetUrl('images/progress.svg') for getting images
    and it returns path which isn't get image
    image.png
    file content looks like this ^
    codemonkeynorth
    @codemonkeynorth
    Have you edited your webpack config at all?
    Oh also check your svg have the correct header. I had trouble on a server with it not recognising them because the xml definition was missing
    Alexander
    @xenx-efy

    Have you edited your webpack config at all?

    no

    codemonkeynorth
    @codemonkeynorth
    Has this been stripped off the top off the SVG. I’m not saying it’s the issue but....
    <?xml version="1.0" encoding="UTF-8"?>
    Alexander
    @xenx-efy

    <?xml version="1.0" encoding="UTF-8"?>

    this did not help, it seems that the problem is in the configuration of the webpack.

    codemonkeynorth
    @codemonkeynorth
    are you saying the svg file actually has that error in the svg file?
    Alexander
    @xenx-efy
    this error happend because webpack put in file content instead svg tag this command export default __webpack_public_path__ + "fonts/progress.c5bcc87d11.svg";
    maybe I don't need to import images in index.js file?
    but it works with png and jpeg extensions
    codemonkeynorth
    @codemonkeynorth
    Can’t work out why it’s putting it in fonts
    Alexander
    @xenx-efy
    me too, welcome to the club)
    codemonkeynorth
    @codemonkeynorth
    I don’t see anything in the webpack config that would do that
    Alexander
    @xenx-efy
    how do it works in your case?
    maybe I really once changed config depends on it
    codemonkeynorth
    @codemonkeynorth
    I’ve never had an issue with it. However... the image you are using in your PHP code. Did you import it somewhere in the js?
    In the past I’ve added a dummy js file to do import of assets I want to use in my php code
    codemonkeynorth
    @codemonkeynorth
    'assets': utils.srcScriptsPath('assets/index.js'), added to build\webpack\entry.js this will spit out an assets.js file that doesn’t need to be used anywhere but makes sure it’s in the manifest to be accessed via the php
    then in that assets/index.js I just do my image imports
    I don’t think this is your issue though . Just saying
    Looking to see if I have an example with svg in
    codemonkeynorth
    @codemonkeynorth
    But for now you can just import in your main index to test
    Alexander
    @xenx-efy
    ok, thx
    codemonkeynorth
    @codemonkeynorth
    On a side note. If you’re using an external svg as an img src, some servers require the xml/doctype header . Let me find example
    Alexander
    @xenx-efy
    that would be nice.
    codemonkeynorth
    @codemonkeynorth
    I had to add this...
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">