Hot answers tagged

5

This is one (of the many) great things about Craft. You can literally include any javascript library however you like. In general, if there is a library you want to use, you can simply follow the guide for that particular library. A traditional approach is to include jQuery in the <head> of your document, then any other scripts after. I personally ...


5

You would use <script> tags in your template, preferable in a _layout.html or _base.html template which you extend from all your other templates.


4

Looks like you're actually off-track in a couple of different ways... ElementCriteriaModel This code is going to return an ElementCriteriaModel: craft.tags.group('gameTags') Think of an ElementCriteriaModel as being a pending search query... The only reason you'd need one is to either adjust the query further or run the query to get results. Fortunately ...


4

In your first example, you are outputting an ElementCriteriaModel. That is a query for tags rather than the tags themselves. It doesn't output anything usable by JS You're almost doing the same in the second example, except that your reference to gameTags in the JS is just referencing itself rather than any Twig output. What you want to do is to query the ...


4

There is no "syntax" for it since you don't parse these files with PHP. You'll have to declare your variables inside a twig file First Approach Twig <script> var myVariable = {{ theme|json_encode|raw }} </script> Javascript jQuery(document).ready(function(){ var uspicon1 = myVariable.usp_1_icon; var uspicon2 = myVariable....


3

The "Craft" javascript global object can only be used in the backend, not on the frontend.


3

Your code looks fine and worked for me when testing locally. However it could be failing due to the fact that you're not url-encoding the parameter before you send the request. If the values contain spaces or other special characters, for example, this would make it fail. To fix that issue, try using encodeURI() like this: $("#second-choice").load("{{ ...


2

One issue may be that your javascript is requesting a specific url as defined from the site root, thus not giving craft the opportunity to do it's locale routing magic (keep in mind the url for languages other than the default locale may actually be '/no/loadmore.html' — or however you have defined the locale routes in your config settings). So just changing ...


2

This seems more like a jquery issue then a craft issue. You might look into jquery's load method. Doing a quick google search I came up with this possible solution, which you would need to adapt. function callIframe(url, callback) { $(document.body).append('<iframe id="myId" ...>'); $('iframe#myId').attr('src', url); $('iframe#myId')....


2

You can use this support article to help debug failed uploads: https://craftcms.com/support/upload-troubleshooting


2

The question you link to - that is a working example really except you a) might not need the CSRF stuff if you haven't turned on CSRF protection (you should, though) - and of course the ... at the end means you should at least finish off the function and do some error handling. In any case, in this specific case, you should just in essence need: $(...


2

Silly me, this has nothing to do with charge.js, one simply can't have a button with an id="submit" as weird things will happen - see this thread <input type="button" id="otherThanSubmit"> this works fine


2

The issue was that curl was, by default, returning the result of the http request to the WebToLead servlet directly, rather than only storing it as $result. This raw HTML response was super-ceding the returnJson() response, resulting in an error in jQuery's ajax function. To force PHP curl to echo the result rather than return it, you need to set a curl ...


2

You can create your own search... lets say this is your html <input type="input" id="searchTags" placeholder="Search"> <input type="button" id="startSearch" value="Go"> <div id="results"></div> then you have the following script: $("#startSearch").click(function(){ var data = { action: 'pluginhandle/controller/...


1

maybe this article will help! https://nystudio107.com/blog/autocomplete-search-with-the-element-api-vuejs


1

Of course there is, otherwise we would not be able to store categories in Craft. The controller that handles categories is called CategoriesController and it contains the function actionSaveCategory so you route will be actions/categories/saveCategory To create/save a user you have the UsersController.. You may guess the function is actionSaveUser => ...


1

Ok so thanks to @BradBell's suggestion, I regenerated the skeleton of my plugin and it's controller using pluginfactory.io and it now magically works! Still not sure exactly what the difference was, but it does its job now!


1

This sounds like a bug and I would raise it with support@craftcommerce.com The stock part of Craft Commerce is still pretty basic at this point.


1

Can confirm this is a bug. Should have it fixed soon.


1

You probably just need to wrap the twig output in a string, if that's what you need in your javascript. Try: <script type="text/javascript"> var gameTags = "{{ craft.tags.group('gameTags') }}"; </script>


Only top voted, non community-wiki answers of a minimum length are eligible